Skip to main content

A custom CSV reader implementation with direct file access

Project description

csv-position-reader

A custom CSV reader implementation with direct file access

The default builtin Python csv lib uses an 8KB read-ahead buffer on the file pointer, making fp.tell() yield inaccurate results. This library addresses that head on, explicitly passing back the file pointer position with each row, as well as allowing for direct seeking.

References:

Usage

>>> import csv_position_reader

>>> with open('tests/data/basic.csv', 'r') as fp:
...     reader = csv_position_reader.DictReader(fp)
...     position, row = reader.next()
...     print "position: %s" % position
...     print "row: %s" % row
...     reader.seek(position)
...     position_new, row_new = reader.next()
...     assert position == position_new
...     assert row == row_new
... 
position: 26
row: {'city': 'Atlanta', 'favorite_color': 'black', 'name': 'Sam'}

Why? / Who Cares?

Because after poring through a CSV one time, you can now build a dictionary/cache of where each row lives for future O(1) access! You're now a stone's throw away from a CSV-driven database!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csv-position-reader-0.1.0.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

csv_position_reader-0.1.0-py2.py3-none-any.whl (3.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file csv-position-reader-0.1.0.tar.gz.

File metadata

  • Download URL: csv-position-reader-0.1.0.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.14

File hashes

Hashes for csv-position-reader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4737871b2b23b3f88b5e3f396d1b41ece7d7477c8aa1f44398cbb660b57ca992
MD5 e0c7117666eceb9da9ef880fb23cc0a2
BLAKE2b-256 e788895c475df026c17db44fd4b9d5c773123844c58e6395f0e99f713e72d124

See more details on using hashes here.

File details

Details for the file csv_position_reader-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: csv_position_reader-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.14

File hashes

Hashes for csv_position_reader-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2e07e479946b0f9fc7a9ad227653abd12f89f5e2f6973d91624c28b4df542afd
MD5 8c272fb0dd865941233ee818a9ccddac
BLAKE2b-256 254b2f1a0f5941263573a44ab956358417f54e6c1b3f6dc30f043d3db042470e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page