civis.io.civis_to_file
- civis.io.civis_to_file(file_id, buf, client=None)[source]
Download a file from Civis.
- Parameters:
- file_idint
The Civis file ID.
- buffile-like object or str
A buffer or path specifying where to write the contents of the Civis file. Strings will be treated as paths to local files to open.
- client
civis.APIClient, optional If not provided, an
civis.APIClientobject will be created from theCIVIS_API_KEY.
- Returns:
- None
Examples
>>> import civis >>> file_id = 100 >>> # Download a file to a path on the local filesystem. >>> civis.io.civis_to_file(file_id, "my_file.txt") >>> # Download a file to a file object. >>> with open("my_file.txt", "wb") as f: ... civis.io.civis_to_file(file_id, f) >>> # Download a file as a bytes object. >>> import io >>> buf = io.BytesIO() >>> civis.io.civis_to_file(file_id, buf) >>> # Note that s could be converted to a string with s.decode('utf-8'). >>> s = buf.read()