civis.io.export_to_civis_file
- civis.io.export_to_civis_file(sql: str, database: str | int, sql_params_arguments: dict | None = None, job_name: str | None = None, client: APIClient | None = None, credential_id: int | None = None, polling_interval: int | float | None = None, hidden: bool = True, csv_settings: dict | None = None) CivisFuture[source]
Store results of a query to a Civis file
- Parameters:
- sqlstr
The SQL select string to be executed.
- databasestr or int
Execute the query against this database. Can be the database name or ID.
- sql_params_argumentsdict, optional
A dictionary of SQL query parameters to pass directly to
civis.APIClient.scripts.post_sql. The only allowed keys are"params"(whose value is a list[dict]) and"arguments"(whose value is a dict). Please refer to the linked API documentation for how to format these two keys’ values.- job_namestr, optional
A name to give the job. If omitted, a random job name will be used.
- client
civis.APIClient, optional If not provided, an
civis.APIClientobject will be created from theCIVIS_API_KEY.- credential_idstr or int, optional
The database credential ID. If
None, the default credential will be used.- polling_intervalint or float, optional
Number of seconds to wait between checks for query completion.
- hiddenbool, optional
If
True(the default), this job will not appear in the Civis UI.- csv_settingsdict, optional
A dictionary of csv_settings to pass to
civis.APIClient.scripts.post_sql().
- Returns:
- fut
CivisFuture A future which returns the response from
civis.APIClient.scripts.get_sql_runs()after the sql query has completed and the result has been stored as a Civis file.
- fut
See also
civis.io.read_civisRead directly into memory without SQL.
civis.io.read_civis_sqlRead results of a SQL query into memory.
civis.io.civis_to_csvWrite directly to a CSV file.
civis.io.civis_file_to_tableUpload a Civis file to a Civis table
Examples
>>> import civis >>> sql = "SELECT * FROM schema.table" >>> fut = civis.io.export_to_civis_file(sql, "my_database") >>> file_id = fut.result()['output'][0]["file_id"]