SQLAlchemyCsvWriter API Reference
Write SQL Alchemy results to a csv file.
Source code in sqlalchemy_csv_writer/writer.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
__enter__()
__init__(csvfile, header=True, prefix_model_names=False, field_formats=None, dialect='excel', **fmtparams)
Create a SQLAlchemyCsvWriter instance.
The instance's methods can be used to write rows to the specified csv file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
csvfile |
Union[Path, str, IO]
|
Path or File-like object to write the resulting csv data to |
required |
header |
Union[list[str], bool]
|
True to automatically generate header, False to disable header or list of strings for custom header |
True
|
prefix_model_names |
bool
|
Whether to prefix the model names in the header |
False
|
field_formats |
Union[dict[str, str], None]
|
Dictionary containing the column name as keys and column format as a values (using % style format syntax) |
None
|
dialect |
csv dialect to use |
'excel'
|
|
**fmtparams |
extra formatting parameters to pass to csv.writer instance |
{}
|
Source code in sqlalchemy_csv_writer/writer.py
write_rows(results)
Write query results to csv.
Write query results retrieved with SQLAlchemy's .execute or .scalars. to csv
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results |
list
|
query results retrieved with SQLAlchemy's .execute or .scalars |
required |
Source code in sqlalchemy_csv_writer/writer.py
write_rows_stream(results)
async
Write query results to csv.
Write query results retrieved with SQLAlchemy's .stream or .stream_scalars.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results |
list
|
query results retrieved with SQLAlchemy's .stream or .stream_scalars |
required |