{"id":26705401,"url":"https://github.com/tangledpath/csv-batcher","last_synced_at":"2025-07-07T19:32:37.598Z","repository":{"id":224091408,"uuid":"762035899","full_name":"tangledpath/csv-batcher","owner":"tangledpath","description":"A utility to split a large CSV into smaller ones, and uses multiprocessing to process the CSVs in parallel.","archived":false,"fork":false,"pushed_at":"2024-06-25T22:24:55.000Z","size":1158,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-09T20:33:57.405Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tangledpath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-02-23T00:35:59.000Z","updated_at":"2024-02-24T00:14:33.000Z","dependencies_parsed_at":"2024-03-13T05:32:53.781Z","dependency_job_id":"b6d6049c-202c-4354-8b96-615859837732","html_url":"https://github.com/tangledpath/csv-batcher","commit_stats":null,"previous_names":["tangledpath/csv-batcher"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tangledpath%2Fcsv-batcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tangledpath%2Fcsv-batcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tangledpath%2Fcsv-batcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tangledpath%2Fcsv-batcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tangledpath","download_url":"https://codeload.github.com/tangledpath/csv-batcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791930,"owners_count":20672666,"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":[],"created_at":"2025-03-27T05:34:10.632Z","updated_at":"2025-03-27T05:34:11.221Z","avatar_url":"https://github.com/tangledpath.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# csv-batcher\n\u003cp\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/tangledpath/csv-batcher/master/csv_batcher.png\" align=\"left\" width=\"512\" height=\"256\"/\u003e\n\u003c/p\u003e\n\u003cp\u003e\u0026nbsp\u003c/p\u003e\n\u003cp\u003e\u0026nbsp\u003c/p\u003e\n\u003cp\u003e\u0026nbsp\u003c/p\u003e\n\u003cp\u003e\u0026nbsp\u003c/p\u003e\n\u003cp\u003e\u0026nbsp\u003c/p\u003e\n\u003cp\u003e\u0026nbsp\u003c/p\u003e\n\u003cp\u003e\u0026nbsp\u003c/p\u003e\n\n## [Vertical scaling]([url](https://en.wikipedia.org/wiki/Scalability#Vertical_or_scale_up))\nA lightweight, python-based, multi-process CSV batcher suitable for use with Pandas dataframes, as a standalone tool, or other tools that deal with large CSV files (or files that require timely processing).\n\n## Installation\npip install csv-batcher\n\n## GitHub\nhttps://github.com/tangledpath/csv-batcher\n\n## Documentation\nhttps://tangledpath.github.io/csv-batcher/csv_batcher.html\n\n## Further excercises\n* Possibly implement pooling with celery (for use in django apps, etc.), which can bring about [horizontal scaling]([url](https://en.wikipedia.org/wiki/Scalability#Horizontal_or_scale_out)).\n\n## Usage\nArguments sent to callback function can be controlled by\ncreating pooler with `callback_with` and the CallbackWith enum\nvalues:\n\n### As dataframe row\n```python\nfrom csv_batcher.csv_pooler import CSVPooler, CallbackWith\n\n# Callback function passed to pooler; accepts a dataframe row\n#   as a pandas Series (via apply)\ndef process_dataframe_row(row):\n    return row.iloc[0]\n\npooler = CSVPooler(\n    \"5mSalesRecords.csv\",\n    process_dataframe_row,\n    callback_with=CallbackWith.DATAFRAME_ROW,\n    pool_size=16\n)\nfor processed_batch in pooler.process():\n    print(processed_batch)\n```\n\n### As dataframe\n```python\nfrom csv_batcher.csv_pooler import CSVPooler, CallbackWith\n\n# Used from process_datafrom's apply:\ndef process_dataframe_row(row):\n    return row.iloc[0]\n\n# Callback function passed to pooler; accepts a dataframe:\ndef process_dataframe(df):\n    foo = df.apply(process_dataframe_row, axis=1)\n    # Or do something more complicated....\n    return len(df)\n\npooler = CSVPooler(\n    \"5mSalesRecords.csv\",\n    process_dataframe,\n    callback_with=CallbackWith.DATAFRAME,\n    pool_size=16\n)\nfor processed_batch in pooler.process():\n    print(processed_batch)\n```\n\n### As CSV filename\n```python\nimport pandas as pd\nfrom csv_batcher.csv_pooler import CSVPooler, CallbackWith\n\n# Used from process_csv_filename's apply:\ndef process_dataframe_row(row):\n    return row.iloc[0]\n\ndef process_csv_filename(csv_chunk_filename):\n    # print(\"processing \", csv_chunk_filename)\n    df = pd.read_csv(csv_chunk_filename, skipinitialspace=True, index_col=None)\n    foo = df.apply(process_dataframe_row, axis=1)\n    return len(df)\n\npooler = CSVPooler(\n    \"5mSalesRecords.csv\",\n    process_csv_filename,\n    callback_with=CallbackWith.CSV_FILENAME,\n    chunk_lines=10000,\n    pool_size=16\n)\nfor processed_batch in pooler.process():\n    print(processed_batch)\n```\n## Development\n### Linting\n```bash\nruff check . # Find linting errors\nruff check . --fix # Auto-fix linting errors (where possible)\n```\n\n### Documentation\n```\n# Shows in browser\npoetry run pdoc csv_batcher\n# Generates to ./docs\npoetry run pdoc csv_batcher -o ./docs\n# OR (recommended)\nbin/build.sh\n```\n\n### Testing\n```bash\nclear; pytest\n```\n\n### Publishing\n```bash\npoetry publish --build -u __token__ -p $PYPI_TOKEN`\n# OR (recommended)\nbin/publish.sh\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftangledpath%2Fcsv-batcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftangledpath%2Fcsv-batcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftangledpath%2Fcsv-batcher/lists"}