{"id":16743423,"url":"https://github.com/gabfl/sql2csv","last_synced_at":"2025-03-17T01:32:10.423Z","repository":{"id":33373518,"uuid":"157882274","full_name":"gabfl/sql2csv","owner":"gabfl","description":"Run MySQL and PostgreSQL queries and store result in CSV","archived":false,"fork":false,"pushed_at":"2024-02-18T18:09:40.000Z","size":56,"stargazers_count":32,"open_issues_count":2,"forks_count":10,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-27T16:22:10.588Z","etag":null,"topics":["csv-converter","mysql","postgresql"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gabfl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-16T14:58:44.000Z","updated_at":"2024-06-30T16:15:04.000Z","dependencies_parsed_at":"2024-10-27T11:52:00.432Z","dependency_job_id":"14e2f686-70ac-4df2-bf6f-de4c569f347a","html_url":"https://github.com/gabfl/sql2csv","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"e45cc2b1536707be599c7ad1fe188a74194978e3"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabfl%2Fsql2csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabfl%2Fsql2csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabfl%2Fsql2csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabfl%2Fsql2csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabfl","download_url":"https://codeload.github.com/gabfl/sql2csv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243836015,"owners_count":20355615,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv-converter","mysql","postgresql"],"created_at":"2024-10-13T01:26:58.015Z","updated_at":"2025-03-17T01:32:10.126Z","avatar_url":"https://github.com/gabfl.png","language":"Python","readme":"# sql2csv\n\n[![Pypi](https://img.shields.io/pypi/v/sql2csv.svg)](https://pypi.org/project/sql2csv)\n[![Build Status](https://github.com/gabfl/sql2csv/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/gabfl/sql2csv/actions)\n[![codecov](https://codecov.io/gh/gabfl/sql2csv/branch/main/graph/badge.svg)](https://codecov.io/gh/gabfl/sql2csv)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://raw.githubusercontent.com/gabfl/sql2csv/main/LICENSE)\n\nRun MySQL and PostgreSQL queries and store the results in CSV.\n\n## Why sql2csv\n\n`sql2csv` is a small utility to run MySQL and PostgreSQL queries and store the output in a CSV file.\n\nIn some environments like when using MySQL or Aurora in AWS RDS, exporting queries' results to CSV is not available with native tools. `sql2csv` is a simple module that offers this feature.\n\n## Installation\n\n```bash\npip3 install sql2csv\n\n# Basic usage\nmysql [...] -e \"SELECT * FROM table\" | sql2csv\n# or\npsql [...] -c \"SELECT * FROM table\" | sql2csv\n```\n\n## Example\n\n### From stdin\n\nFor simple queries you can pipe a result directly from `mysql` or `psql` to `sql2csv`.\n\nFor more complex queries, it is recommended to use the CLI (see below) to ensure a properly formatted CSV.\n\n```bash\nmysql -U root -p\"secret\" my_db -e \"SELECT * FROM some_mysql_table;\" | sql2csv\n\nid,some_int,some_str,some_date\n1,12,hello world,2018-12-01 12:23:12\n2,15,hello,2018-12-05 12:18:12\n3,18,world,2018-12-08 12:17:12\n```\n\n```bash\npsql -U postgres my_db -c \"SELECT * FROM some_pg_table\" | sql2csv\n\nid,some_int,some_str,some_date\n1,12,hello world,2018-12-01 12:23:12\n2,15,hello,2018-12-05 12:18:12\n3,18,world,2018-12-08 12:17:12\n```\n\n### Using `sql2csv` CLI\n\n#### Output to stdout\n\n```bash\n$ sql2csv --engine mysql \\\n  --database my_db --user root --password \"secret\" \\\n  --query \"SELECT * FROM some_mysql_table\"\n\n1,12,hello world,2018-12-01 12:23:12\n2,15,hello,2018-12-05 12:18:12\n3,18,world,2018-12-08 12:17:12\n```\n\n#### Output saved in a file\n\n```bash\n$ sql2csv --engine mysql \\\n  --database my_db --user root --password \"secret\" \\\n  --query \"SELECT * FROM some_mysql_table\" \\\n  --headers \\\n  --out file --destination_file export.csv\n\n# * Exporting rows...\n#   ...done\n# * The result has been exported to export.csv.\n\n$ cat export.csv \nid,some_int,some_str,some_date\n1,12,hello world,2018-12-01 12:23:12\n2,15,hello,2018-12-05 12:18:12\n3,18,world,2018-12-08 12:17:12\n```\n\n## Usage\n\n```bash\nusage: sql2csv [-h] [-e {mysql,postgresql}] [-H HOST] [-P PORT] -u USER\n               [-p PASSWORD] -d DATABASE -q QUERY [-o {stdout,file}]\n               [-f DESTINATION_FILE] [-D DELIMITER] [-Q QUOTECHAR] [-t]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -e {mysql,postgresql}, --engine {mysql,postgresql}\n                        Database engine\n  -H HOST, --host HOST  Database host\n  -P PORT, --port PORT  Database port\n  -u USER, --user USER  Database user\n  -p PASSWORD, --password PASSWORD\n                        Database password\n  -d DATABASE, --database DATABASE\n                        Database name\n  -q QUERY, --query QUERY\n                        SQL query\n  -o {stdout,file}, --out {stdout,file}\n                        CSV destination\n  -f DESTINATION_FILE, --destination_file DESTINATION_FILE\n                        CSV destination file\n  -D DELIMITER, --delimiter DELIMITER\n                        CSV delimiter\n  -Q QUOTECHAR, --quotechar QUOTECHAR\n                        CSV quote character\n  -t, --headers         Include headers\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabfl%2Fsql2csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabfl%2Fsql2csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabfl%2Fsql2csv/lists"}