{"id":13424514,"url":"https://github.com/ashtum/lazycsv","last_synced_at":"2025-11-06T23:03:32.099Z","repository":{"id":93289369,"uuid":"280117659","full_name":"ashtum/lazycsv","owner":"ashtum","description":"A fast, lightweight and single-header C++ csv parser library","archived":false,"fork":false,"pushed_at":"2025-05-16T16:55:10.000Z","size":390,"stargazers_count":86,"open_issues_count":0,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-11T14:18:19.612Z","etag":null,"topics":["cpp","cpp-csv-parser","cpp-csv-reader","csv-parser","csv-reader","fast-cpp-csv-parser","parsing-csv-files"],"latest_commit_sha":null,"homepage":"","language":"C++","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/ashtum.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,"zenodo":null}},"created_at":"2020-07-16T09:54:31.000Z","updated_at":"2025-07-08T10:05:05.000Z","dependencies_parsed_at":"2025-05-14T11:28:53.412Z","dependency_job_id":"cb13f561-227d-49c1-9416-27d0dcb9a159","html_url":"https://github.com/ashtum/lazycsv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ashtum/lazycsv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashtum%2Flazycsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashtum%2Flazycsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashtum%2Flazycsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashtum%2Flazycsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashtum","download_url":"https://codeload.github.com/ashtum/lazycsv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashtum%2Flazycsv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283095890,"owners_count":26778518,"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","status":"online","status_checked_at":"2025-11-06T02:00:06.180Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cpp","cpp-csv-parser","cpp-csv-reader","csv-parser","csv-reader","fast-cpp-csv-parser","parsing-csv-files"],"created_at":"2024-07-31T00:00:55.427Z","updated_at":"2025-11-06T23:03:32.084Z","avatar_url":"https://github.com/ashtum.png","language":"C++","readme":"[![CI](https://github.com/ashtum/lazycsv/actions/workflows/ci.yml/badge.svg)](https://github.com/ashtum/lazycsv/actions/workflows/ci.yml)\n\n![lazycsv](img/logo.png)\n\n## What's the lazycsv?\n\n**lazycsv** is a c++17, single-header library for reading and parsing csv files.  \nIt's fast and lightweight and does not allocate any memory in the constructor or while parsing. It parses each row and cell just on demand on each iteration, that's why it's called lazy.\n\n### Quick usage\n\nThe latest version of the single header can be downloaded from [`include/lazycsv.hpp`](include/lazycsv.hpp).\n\n```c++\n#include \u003clazycsv.hpp\u003e\n\nint main()\n{\n    lazycsv::parser parser{ \"contacts.csv\" };\n    for (const auto row : parser)\n    {\n        const auto [id, name, phone] = row.cells(0, 1, 4); // indexes must be in ascending order\n    }\n}\n```\n\n### Performance note\n\nParser doesn't keep state of already parsed rows and cells, iterating through them always associated with parsing cost. This is true with `cells()` member function too, geting all needed cells by a single call is recommended.  \nIf it's necessary to return to the already parsed rows and cells, they can be stored in a container and used later without being parsed again (they are view objects and efficient to copy).\n\n### Features\n\nReturned `std::string_view` by `raw()` and `trimmed()` member functions are valid as long as the parser object is alive:\n\n```c++\nstd::vector\u003cstd::string_view\u003e cities;\nfor (const auto row : parser)\n{\n    const auto [city, state] = row.cells(0, 1);\n    cities.push_back(city.trimmed());\n}\n```\n\nIterate through rows and cells:\n\n```c++\nfor (const auto row : parser)\n{\n    for (const auto cell : row)\n    {\n    }\n}\n```\n\nGet header row and iterate through its cells:\n\n```c++\nauto header = parser.header();\nfor (const auto cell : header)\n{\n}\n```\n\nFind column index by its name:\n\n```c++\nauto city_index = parser.index_of(\"city\");\n```\n\n`row` and `cell` are view objects on actual data in the parser object, they can be stored and used as long as the parser object is alive:\n\n```c++\nstd::vector\u003clazycsv::parser\u003c\u003e::row\u003e desired_rows;\nstd::vector\u003clazycsv::parser\u003c\u003e::cell\u003e desired_cells;\nfor (const auto row : parser)\n{\n    const auto [city] = row.cells(6);\n    desired_cells.push_back(city);\n\n    if (city.trimmed() == \"Kashan\")\n        desired_rows.push_back(row);\n}\nstatic_assert(sizeof(lazycsv::parser\u003c\u003e::row) == 2 * sizeof(void*));  // i'm lightweight\nstatic_assert(sizeof(lazycsv::parser\u003c\u003e::cell) == 2 * sizeof(void*)); // i'm lightweight too\n```\n\nParser is customizable with the template parameters:\n\n```c++\nlazycsv::parser\u003c\n    lazycsv::mmap_source,           /* source type of csv data */\n    lazycsv::has_header\u003ctrue\u003e,      /* first row is header or not */\n    lazycsv::delimiter\u003c','\u003e,        /* column delimiter */\n    lazycsv::quote_char\u003c'\"'\u003e,       /* quote character */\n    lazycsv::trim_chars\u003c' ', '\\t'\u003e\u003e /* trim characters of cells */\n    my_parser{ \"data.csv\" };\n```\n\nBy default parser uses `lazycsv::mmap_source` as its source of data, but it's possible to be used with any other types of contiguous containers:\n\n```c++\nstd::string csv_data{ \"name,lastname,age\\nPeter,Griffin,45\\nchris,Griffin,14\\n\" };\n\nlazycsv::parser\u003cstd::string_view\u003e parser_a{ csv_data };\nlazycsv::parser\u003cstd::string\u003e parser_b{ csv_data };\n```\n\n## Acknowledgments\n\n- [Wang XiHua](https://github.com/kabxx) for adding Windows support and cross-platform line ending.\n","funding_links":[],"categories":["CSV","File Formats"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashtum%2Flazycsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashtum%2Flazycsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashtum%2Flazycsv/lists"}