Write SQLAlchemy results to csv files
Project description
SQLAlchemyCsvWriter
SQLAlchemyCsvWriter is a thin wrapper around the python csw.writer function to make the process of exporting SQLAlchemy query results to csv simpler.
It supports both synchronous as well as asynchronous query results, as well as streaming.
Features
- Write SQLAlchemy query results to csv file with little boilerplate
- Optionally write header by auto generation or passing column names
- Supports same dialect and formatting parameters as csv.writer
- Supports synchronous, asynchronous and asynchronous streaming results
- Supports any models defined with DeclarativeBase
Installation
- with pip:
pip install sqlalchemy-csv-writer
- with poetry:
poetry add sqlalchemy-csv-writer
Usage
from sqlalchemy_csv_writer import SQLAlchemyCsvWriter
with SQLAlchemyCsvWriter(
"test.csv",
header=True,
field_formats={"column_1": "%.2f"},
prefix_model_names=True,
dialect="unix",
) as writer:
writer.write_rows(results) # pass results of SQLAlchemy query
For full example see examples directory (uses the alchemical SQLAlchemy wrapper).
Development Notes
- Linting and formatting using ruff
- Testing using pytest
- Dependency management and release using poetry
- Documentation using mkdocs with mkdocs-material and other plugins, released to GitHub pages
- CI/CD using GitHub Actions
- Pull requests are welcome
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for sqlalchemy_csv_writer-0.4.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | babd0f86ca3217bc002121fbe9d71916ecfaba27ebd18641161ed17c71300788 |
|
MD5 | 7a30a00fc51a7d92522ad9caeddf6211 |
|
BLAKE2b-256 | 375ff460d975db57cc142124361f936fc5675211bef86e18c2356b1a71da27d8 |
Close
Hashes for sqlalchemy_csv_writer-0.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12d5d4eea9f7cb4a9d3f61f5784489f8796247a43258d37f4700c90c154d1f22 |
|
MD5 | b584cae3db93f706d36d5057b2bd4cd1 |
|
BLAKE2b-256 | 7f336398e509a7bd463dd627e927f7676ebf3eaf88bf7528dcffd950b354aa7a |