{"id":17892173,"url":"https://github.com/shir0kamii/flask-csv","last_synced_at":"2025-03-22T23:32:53.042Z","repository":{"id":57430238,"uuid":"90185188","full_name":"Shir0kamii/Flask-CSV","owner":"Shir0kamii","description":"Easily render CSVs within any flask application","archived":false,"fork":false,"pushed_at":"2023-12-10T00:10:34.000Z","size":18,"stargazers_count":20,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-23T19:07:54.707Z","etag":null,"topics":["api","csv","flask","flask-extensions"],"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/Shir0kamii.png","metadata":{"files":{"readme":"README.rst","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":"2017-05-03T19:21:20.000Z","updated_at":"2023-12-09T21:53:10.000Z","dependencies_parsed_at":"2024-06-21T16:53:42.879Z","dependency_job_id":"f3a61605-b827-4bbe-bb94-4201cbc4cafb","html_url":"https://github.com/Shir0kamii/Flask-CSV","commit_stats":{"total_commits":32,"total_committers":5,"mean_commits":6.4,"dds":0.21875,"last_synced_commit":"b32ad338d4b3fc0be695d58b424362b7f82d6dea"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shir0kamii%2FFlask-CSV","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shir0kamii%2FFlask-CSV/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shir0kamii%2FFlask-CSV/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Shir0kamii%2FFlask-CSV/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Shir0kamii","download_url":"https://codeload.github.com/Shir0kamii/Flask-CSV/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221840921,"owners_count":16889895,"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":["api","csv","flask","flask-extensions"],"created_at":"2024-10-28T14:34:02.883Z","updated_at":"2024-10-28T14:34:03.335Z","avatar_url":"https://github.com/Shir0kamii.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"#########\nFlask-CSV\n#########\n\nEasily render CSVs within any flask application\n\nInstall\n#######\n\nFlask-CSV is packaged and you can use pip to install it::\n\n    pip install flask_csv\n\n\nHow to use ?\n############\n\nFlask-CSV has a simple hepler method named `send_csv` which allows you to send\ncsv files in flask endpoints. It takes an iterable of `dict`, a filename and a\nlist of fields. The keys of all `dict` in the iterable must correspond to\ngiven fields.\n\nIt will return a `Response` object with filename set and body containing the\nCSV data.\n\nYou will better understand with a short example.\n\n.. code-block:: python\n\n    @app.route(\"/\")\n    def index():\n        return send_csv([{\"id\": 42, \"foo\": \"bar\"}, {\"id\": 91, \"foo\": \"baz\"}],\n                        \"test.csv\", [\"id\", \"foo\"])\n\nHitting this endpoint will return::\n\n    id,foo\n    42,bar\n    91,baz\n\n\nPassing additionnal parameters\n##############################\n\nThe remaining arguments of `send_csv` will be passed to `send_file`. For\nexample, to disable caching, do the following:\n\n.. code-block:: python\n\n    send_csv([{\"id\": 42, \"foo\": \"bar\"}, {\"id\": 91, \"foo\": \"baz\"}],\n             \"test.csv\", [\"id\", \"foo\"], cache_timeout=0)\n\nYou can also pass additionnal parameters to the CSV writer like this:\n\n.. code-block:: python\n\n    send_csv([{\"foo\": 42}, {\"bar\": \"baz\"}], \"test.csv\", [\"foo\"],\n             writer_kwargs={\"extrasaction\": \"ignore\"})\n\nIn this example, the \"bar\" key will not raise a `ValueError` since the writer\nwill be given the parameter `extrasaction` with the value \"ignore\".\n\n\nChange delimiter\n################\n\nYou can also change the delimiter with the `delimiter` option.\n\n.. code-block:: python\n\n    send_csv([{\"id\": 42, \"foo\": \"bar\"}, {\"id\": 91, \"foo\": \"baz\"}],\n             \"test.csv\", [\"id\", \"foo\"], delimiter=';')\n\nWill result in::\n\n    id;foo\n    42;bar\n    91;baz\n\nSpecifying file encoding\n########################\n\nYou can also specify the encoding used to send the file, with the `encoding` option (`utf-8` by default).\n\n.. code-block:: python\n\n    send_csv([{\"id\": 42, \"foo\": \"bar\"}, {\"id\": 91, \"foo\": \"baz\"}],\n             \"test.csv\", [\"id\", \"foo\"], encoding='iso-8859-1')\n\nUse Marshmallow Schemas\n#######################\n\nYou can use `Schema` from marshmallow by passing it as `schema` to `send_csv`.\nIf you want to keep only ids and ensure they are integers, you could do:\n\n.. code-block:: python\n\n    class IdSchema(Schema):\n        id = fields.Integer()\n\n    send_csv([{\"id\": 42, \"foo\": \"bar\"}, {\"id\": 91, \"foo\": \"baz\"}],\n             \"test.csv\", [\"id\", \"foo\"], schema=IdSchema())\n\nAnd that would result in this::\n\n    id\n    42\n    91\n\nSystemError returned a result with an error set\n###############################################\n\nWhen using uwsgi for your flask app, it might raise this kind of error on the send_file method.\nIf that were the case, adding the following option to your uwsgi conf should solve it :\n\n`wsgi-disable-file-wrapper = true`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshir0kamii%2Fflask-csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshir0kamii%2Fflask-csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshir0kamii%2Fflask-csv/lists"}