# SQLAlchemyCsvWriter
[![Stable Version](https://img.shields.io/pypi/v/sqlalchemy_csv_writer?label=stable)](https://pypi.org/project/sqlalchemy-csv-writer/#history)
![Python Versions](https://img.shields.io/pypi/pyversions/sqlalchemy_csv_writer)
![Tests](https://github.com/github/docs/actions/workflows/test.yml/badge.svg?branch=main)
[![codecov](https://codecov.io/gh/raayu83/sqlalchemy-csv-writer/graph/badge.svg?token=TXRKRRADUH)](https://codecov.io/gh/raayu83/sqlalchemy-csv-writer)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
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](https://docs.python.org/3/library/csv.html#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
```python
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](https://github.com/miguelgrinberg/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
Raw data
{
"_id": null,
"home_page": "https://raayu83.github.io/sqlalchemy-csv-writer/",
"name": "sqlalchemy-csv-writer",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "",
"keywords": "sqlalchemy,csv",
"author": "Rayuu83",
"author_email": "rayuu83@spellweb.de",
"download_url": "https://files.pythonhosted.org/packages/37/5f/f460d975db57cc142124361f936fc5675211bef86e18c2356b1a71da27d8/sqlalchemy_csv_writer-0.4.2.tar.gz",
"platform": null,
"description": "# SQLAlchemyCsvWriter\n\n[![Stable Version](https://img.shields.io/pypi/v/sqlalchemy_csv_writer?label=stable)](https://pypi.org/project/sqlalchemy-csv-writer/#history)\n![Python Versions](https://img.shields.io/pypi/pyversions/sqlalchemy_csv_writer)\n![Tests](https://github.com/github/docs/actions/workflows/test.yml/badge.svg?branch=main)\n[![codecov](https://codecov.io/gh/raayu83/sqlalchemy-csv-writer/graph/badge.svg?token=TXRKRRADUH)](https://codecov.io/gh/raayu83/sqlalchemy-csv-writer)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)\n\nSQLAlchemyCsvWriter is a thin wrapper around the python csw.writer function to make the process of exporting SQLAlchemy query results to csv simpler. \n\nIt supports both synchronous as well as asynchronous query results, as well as streaming.\n\n## Features\n- Write SQLAlchemy query results to csv file with little boilerplate\n- Optionally write header by auto generation or passing column names\n- Supports same dialect and formatting parameters as [csv.writer](https://docs.python.org/3/library/csv.html#csv.writer)\n- Supports synchronous, asynchronous and asynchronous streaming results\n- Supports any models defined with DeclarativeBase\n\n## Installation\n- with pip: `pip install sqlalchemy-csv-writer`\n- with poetry: `poetry add sqlalchemy-csv-writer`\n\n## Usage\n\n```python\nfrom sqlalchemy_csv_writer import SQLAlchemyCsvWriter\n\nwith SQLAlchemyCsvWriter(\n \"test.csv\",\n header=True,\n field_formats={\"column_1\": \"%.2f\"},\n prefix_model_names=True,\n dialect=\"unix\",\n) as writer:\n writer.write_rows(results) # pass results of SQLAlchemy query\n```\n\nFor full example see examples directory (uses the [alchemical](https://github.com/miguelgrinberg/alchemical) SQLAlchemy wrapper).\n\n## Development Notes\n- Linting and formatting using ruff\n- Testing using pytest\n- Dependency management and release using poetry\n- Documentation using mkdocs with mkdocs-material and other plugins, released to GitHub pages\n- CI/CD using GitHub Actions\n- Pull requests are welcome",
"bugtrack_url": null,
"license": "",
"summary": "Write SQLAlchemy results to csv files",
"version": "0.4.2",
"project_urls": {
"Homepage": "https://raayu83.github.io/sqlalchemy-csv-writer/",
"Repository": "https://github.com/raayu83/sqlalchemy-csv-writer"
},
"split_keywords": [
"sqlalchemy",
"csv"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7f336398e509a7bd463dd627e927f7676ebf3eaf88bf7528dcffd950b354aa7a",
"md5": "b584cae3db93f706d36d5057b2bd4cd1",
"sha256": "12d5d4eea9f7cb4a9d3f61f5784489f8796247a43258d37f4700c90c154d1f22"
},
"downloads": -1,
"filename": "sqlalchemy_csv_writer-0.4.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b584cae3db93f706d36d5057b2bd4cd1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 4901,
"upload_time": "2023-11-19T16:16:27",
"upload_time_iso_8601": "2023-11-19T16:16:27.652165Z",
"url": "https://files.pythonhosted.org/packages/7f/33/6398e509a7bd463dd627e927f7676ebf3eaf88bf7528dcffd950b354aa7a/sqlalchemy_csv_writer-0.4.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "375ff460d975db57cc142124361f936fc5675211bef86e18c2356b1a71da27d8",
"md5": "7a30a00fc51a7d92522ad9caeddf6211",
"sha256": "babd0f86ca3217bc002121fbe9d71916ecfaba27ebd18641161ed17c71300788"
},
"downloads": -1,
"filename": "sqlalchemy_csv_writer-0.4.2.tar.gz",
"has_sig": false,
"md5_digest": "7a30a00fc51a7d92522ad9caeddf6211",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 4491,
"upload_time": "2023-11-19T16:16:28",
"upload_time_iso_8601": "2023-11-19T16:16:28.946711Z",
"url": "https://files.pythonhosted.org/packages/37/5f/f460d975db57cc142124361f936fc5675211bef86e18c2356b1a71da27d8/sqlalchemy_csv_writer-0.4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-19 16:16:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "raayu83",
"github_project": "sqlalchemy-csv-writer",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "sqlalchemy-csv-writer"
}