Skip to main content

A Python library providing fast access to data in very large delimited data files (CSV, TSV, pipe-delimited, etc).

Project description

SeeSV

SeeSV is a library for providing fast access to data in very large delimited data files (CSV, TSV, pipe-delimited, etc) as memory-efficient as possible.

This library grew out of the frustration of reading and analyzing very large (multi-gigabyte, 5+ million row) CSV files (and other delimited file formats). There are few options for reading these files to quickly find problems, generate a filtered subset, or find specific data. There was the constant need for both a command line tool that can be used on a server via an SSH terminal connection and a desktop tool that can quickly churn through huge files. There are many tools out there, but most fall flat when handling very large files - either they take forever to open the file or (and) end up crashing by running out of memory.

The goal with SeeSV is to provide both a re-usable library that encapsulates handling delimited files and a cross-platform desktop GUI that builds on top of the library to provide the user with the best possible experience and feature set.

This project provides the re-usable Python library that can be used to build tools or programmatically inspect files.

Design

SeeSV Features

  • Blazing fast loading of files so that the user gets to a productive state with the data within seconds.
  • Minimal memory consumption even for extremely large files.
  • The ability to jump to any area of a file in constant time, then provide a bounded or unbounded stream of parsed records from that point.
  • Handle files with or without headers, and files with extra header lines (like file summary metadata, etc).
  • Simple, intuitive API

Design

When a file is opened, SeeSV performs a number of discovery tasks:

  1. Extract the column headers, if the file contains any. The headers are stored in a list accessible as a property of the DelimitedFile object.
  2. Scans the file to generate an internal index of the byte positions of the start of every line (row) in the file, excluding the headers. This index is the only aspect of SeeSV that may use a significant amount of memory. In testing, the scan of a 5 million row file (2.3GB) took around 4 seconds and produced an index using 18MB of memory. The index enables a constant-time seek to any part of a file by row number.
  3. As a consequence of step 2, the row count is obtained and made available as a property of the DelimitedFile object.
  4. File size is also made available through a property.

The DelimitedFile class encapsulates all of the functionality. It is implemented as a context manager, allowing with the with block to ensure that the source file is closed and memory released when done with the file. Use of the context manager interface is optional, and a developer can choose the manual route of calling .open() and .close().

Development

SeeSV uses Poetry to build and publish. Poetry's excellent dependency management feature is not needed, since SeeSV has no dependencies. However, Poetry comes in handy for managing the development environment.

To get started with working on the code, first get Poetry installed, then follow these steps:

Create a new virtual environment for the project (or use the currently activated one)

poetry shell

Get the development dependencies installed (pytest, flake8, etc)

poetry install

This command also installs the seesv library into the virtual environment's site_packages.

Build the code

poetry build

This generates both an sdist(tar.gz file) and a Wheel file that can then be installed using Pip.

Examples

Example 1: a file with the context manager interface, assuming that the file has a header line:

from seesv import DelimitedFile
...

with DelimitedFile('/path/to/test.csv') as csv_file:
    ...
    # Array of column headers is available as csv_file.header
    
    # Get 1,000 rows starting from row 25,000
    for row in csv_file.get_rows(25000, 1000):
        # work with row

Example 2: Similar to Example 1, except the file contains two extra metadata lines at the top before the column headers that we want to skip:

with DelimitedFile('/path/to/test.csv', skip_rows=2) as csv_file:
    ...
    # Get 1,000 rows starting from row 25,000
    for row in csv_file.get_rows(25000, 1000):
        # work with row

Example 3: The file does not contain a header row, so we just want access to the data:

with DelimitedFile('/path/to/test.csv', has_header=False) as csv_file:
    ...
    # csv_file.header is not populated
    
    # Get 1,000 rows starting from row 25,000
    for row in csv_file.get_rows(25000, 1000):
        # work with row

Example 4: We don't want to use the context manager interface:

csv_file = DelimitedFile('/path/to/test.csv')
csv_file.open()
...
csv_file.close()

Example 5: We just want to get a single row from the file:

with DelimitedFile('/path/to/test.csv') as csv_file:
    row = csv_file.get_row(1500)
    
    # Get the last row of the file
    row = csv_file.get_row(csv_file.rowCount)

Example 6: Get all rows from a given point till the end of the file:

with DelimitedFile('/path/to/test.csv') as csv_file:
    for row in csv_file.get_rows(1500):
        ...
    # Get last 100 rows in the file
    for row in csv_file.get_rows(csv_file.rowCount - 100):
        ...

Roadmap

The following are some of the features that are coming:

  • Automatically detect column data types
  • Allow user to supply column schema.
  • Support for file formats other than CSV:
    • Tab-separated
    • Pipe-delimited
    • JSON (?)
    • Compressed files (e.g. myfile.csv.gz)
  • Auto-detect which line contains headers (e.g. ignore any metadata rows at the top of the file)
  • Filters
  • SQL Queries
  • Projections - get specified columns instead of all columns

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

seesv-0.1.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

seesv-0.1.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file seesv-0.1.2.tar.gz.

File metadata

  • Download URL: seesv-0.1.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Windows/10

File hashes

Hashes for seesv-0.1.2.tar.gz
Algorithm Hash digest
SHA256 95b83a5c4dfa09150c47c26e631e6c48637a864688a5a934be51124509bb79b2
MD5 ae265d802b47c39e942ad10436f3d761
BLAKE2b-256 dfeb8aee2ba203bb88b1f350aa4f6a1ca91adbd47fd5652f79ba11eb76900b80

See more details on using hashes here.

File details

Details for the file seesv-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: seesv-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Windows/10

File hashes

Hashes for seesv-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 da0c7b4c6a56a3ed489e861ca36cb84abf57d5cef0bf97f7d80578c8d37c82dc
MD5 c04646cebafb1e2fb33c8df44de67a60
BLAKE2b-256 5184c88a44d2f7a24c9f1c2165d14fb5e4c3d055825b0ca1bfcdd48886f1c605

See more details on using hashes here.

Supported by

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