{"id":16346387,"url":"https://github.com/milesgranger/flaco","last_synced_at":"2025-03-20T23:32:47.629Z","repository":{"id":38314002,"uuid":"411382477","full_name":"milesgranger/flaco","owner":"milesgranger","description":"(PoC) A very memory-efficient way to read data from PostgreSQL","archived":false,"fork":false,"pushed_at":"2022-10-28T04:08:27.000Z","size":149,"stargazers_count":15,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-01T00:58:25.278Z","etag":null,"topics":["arrow","postgresql","pyarrow","python","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/milesgranger.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}},"created_at":"2021-09-28T17:42:53.000Z","updated_at":"2024-09-04T21:39:12.000Z","dependencies_parsed_at":"2023-01-19T14:48:48.225Z","dependency_job_id":null,"html_url":"https://github.com/milesgranger/flaco","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milesgranger%2Fflaco","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milesgranger%2Fflaco/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milesgranger%2Fflaco/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milesgranger%2Fflaco/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milesgranger","download_url":"https://codeload.github.com/milesgranger/flaco/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244092755,"owners_count":20396866,"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":["arrow","postgresql","pyarrow","python","rust"],"created_at":"2024-10-11T00:35:14.131Z","updated_at":"2025-03-20T23:32:47.264Z","avatar_url":"https://github.com/milesgranger.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## flaco\n\n[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)\n[![CI](https://github.com/milesgranger/flaco/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/milesgranger/flaco/actions/workflows/CI.yml)\n[![PyPI](https://img.shields.io/pypi/v/flaco.svg)](https://pypi.org/project/flaco)\n![PyPI - Wheel](https://img.shields.io/pypi/wheel/flaco)\n[![Downloads](https://pepy.tech/badge/flaco/month)](https://pepy.tech/project/flaco)\n\n---\n\n#### Install:\n\n`pip install flaco`\n\n---\n\nThe easiest and perhaps most memory efficient way to get PostgreSQL data (more flavors to come?)\ninto `pyarrow.Table`, `pandas.DataFrame` or Arrow (IPC/Feather) and Parquet files. \n\nSince [Arrow](https://github.com/apache/arrow) supports efficient and even larger-than-memory processing,\nas with [dask](https://github.com/dask/dask), [duckdb](https://duckdb.org/), or others.\nJust getting data onto disk is sometimes the hardest part; this aims to make that easier. \n\nAPI:\n`flaco.read_sql_to_file`: Read SQL query into Feather or Parquet file.\n`flaco.read_sql_to_pyarrow`: Read SQL query into a pyarrow table.\n\nNOTE:\nThis is still a WIP. I intend to generalize it more to be\nuseful towards a wider audience. Issues and pull requests welcome!\n\n---\n\n### Example\n\n```bash\nLine #    Mem usage    Increment  Occurrences   Line Contents\n=============================================================\n   122    147.9 MiB    147.9 MiB           1   @profile\n   123                                         def memory_profile():\n   124    147.9 MiB      0.0 MiB           1       stmt = \"select * from test_table\"\n   125\n   126                                             # Read SQL to file\n   127    150.3 MiB      2.4 MiB           1       flaco.read_sql_to_file(DB_URI, stmt, 'result.feather', flaco.FileFormat.Feather)\n   128    150.3 MiB      0.0 MiB           1       with pa.memory_map('result.feather', 'rb') as source:\n   129    150.3 MiB      0.0 MiB           1           table1 = pa.ipc.open_file(source).read_all()\n   130    408.1 MiB    257.8 MiB           1           table1_df1 = table1.to_pandas()\n   131\n   132                                             # Read SQL to pyarrow.Table\n   133    504.3 MiB     96.2 MiB           1       table2 = flaco.read_sql_to_pyarrow(DB_URI, stmt)\n   134    644.1 MiB    139.8 MiB           1       table2_df = table2.to_pandas()\n   135\n   136                                             # Pandas\n   137    648.8 MiB      4.7 MiB           1       engine = create_engine(DB_URI)\n   138   1335.4 MiB    686.6 MiB           1       _pandas_df = pd.read_sql(stmt, engine)\n```\n\n---\n\n### License\n\n\u003e _Why did you choose such lax licensing? Could you change to a copy left license, please?_\n\n...just kidding, no one would ask that. This is dual licensed under \n[Unlicense](LICENSE) or [MIT](LICENSE-MIT), at your discretion.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilesgranger%2Fflaco","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilesgranger%2Fflaco","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilesgranger%2Fflaco/lists"}