Skip to main content

Datapy

An intuitive lightweight file based database and query tool.

  • Query csv files with SQL, without setting up a database
  • An approachable alternative to grep and awk: columns by name, flags you can guess
  • Works in a pipeline and on files larger than memory
  • No dependencies outside the Python standard library
  • Read-only: your data files are never modified

Installation

Datapy needs Python 3.10 or newer.

pip install datapy

Usage

Given people.csv:

name,age,job
Ann,49,engineer
Bob,7,student

Select every column with -sa and the file name:

$ datapy -sa people.csv
name,age,job
Ann,49,engineer
Bob,7,student

Narrow it down and sort it with -w (where) and -o (order):

$ datapy -sa people.csv -w 'age > 40' -o name
name,age,job
Ann,49,engineer

Choose columns with -s, by header name or by position ($1 is the first column):

$ datapy -s name,job people.csv -w 'age > 40'
name,job
Ann,engineer

$ datapy -s '$1' people.csv -w '$2 < 18'
name
Bob

Building a query from flags

datapy -sa FILE [-w CONDITION] [-g COLUMNS] [-o COLUMNS] [-l COUNT]
datapy -s COLUMNS FILE [-w CONDITION] [-g COLUMNS] [-o COLUMNS] [-l COUNT]
Flag Meaning Example
-s, --select choose columns -s name,job
-a, --all with -s, all columns -sa
-w, --where only rows matching a condition -w 'age > 40'
-o, --order sort -o name, -o 'age desc'
-g, --group one row per distinct value -s 'job, count(*)' -g job
-l, --limit at most this many rows -l 10

Each flag is followed by its value, and the flags can come in any order. Repeat -w to require several conditions.

Put each value in single quotes. Without them the shell treats > and < as redirects and expands * and $1 before datapy sees them. Use double quotes when the value contains text in single quotes:

datapy -sa people.csv -w "name = 'Ann'"

Pipes and large files

Leave the file out to read standard input. Results are written as csv, so datapy fits anywhere in a pipeline:

cat people.csv | datapy -sa -w 'age > 40' | head

Rows are read and written as they go. Picking columns and filtering rows takes a small, fixed amount of memory on a file of any size; sorting, grouping and counting use temporary disk space instead of memory. See large files, pipes and memory for details and measurements.

If you know SQL

-q takes everything from where to the end as one string, in place of -w, -g, -o and -l. Or pass a whole statement as a single argument:

datapy -sa people.csv -q 'where age > 40 order by name limit 5'
datapy 'select name, job from people.csv where age > 40'

datapy --help lists every flag, as does the command line reference.

From Python

Open a file in a with block and query it as often as you like. The file is read once, when it is opened:

import datapy

with datapy.open("people.csv") as people:
    print(people.columns)                      # ['name', 'age', 'job']

    for row in people.query("select name, age from people.csv where age > 40"):
        print(row["name"], row[1])             # by column name or position

    minors = people.query("select $1 from people where $2 < 18")
    print(len(minors))

Statements are the same ones the command line accepts. Inside the block the from clause can name the file by its path, its file name (people.csv) or just its name without the extension (people).

For a result too large to hold in memory, datapy.stream() hands the rows over one at a time:

with datapy.stream("select name from people.csv where age > 40") as rows:
    for row in rows:
        print(row["name"])

Problems with a file or a statement raise datapy.DatapyError. The Python API reference has the details.

What a query can do

One select statement against one file. The statement is run by SQLite, so where, order by, group by, limit and SQLite's built-in functions all work. A column is treated as numeric when every value in it is a number, so age > 40 compares numbers rather than text. That is decided from the first 1,000 rows; -t zip keeps a column as text.

See what a query can do for the full rules and limits.

Development

See CONTRIBUTING.md for setup, the code layout and the checks that run before a release. Changes are listed in CHANGELOG.md.

Want to contribute? Great!

This project was originated as a way to bring a community together for Hacktoberfest. I'm glad to have community involvement and help others to understand databases on a more basic level.

License

Apache 2.0

Metadata

Release files for datapy 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datapy 0.2.0
File Size Uploaded Provenance Actions
datapy-0.2.0.tar.gz 28.2 kB With provenance Details for datapy-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datapy 0.2.0
File Interpreter ABI Platform Actions
datapy-0.2.0-py3-none-any.whl Python 3 none any Details for datapy-0.2.0-py3-none-any.whl

Total release size: 49.6 kB

Release files / datapy-0.2.0.tar.gz

Download URL datapy-0.2.0.tar.gz
Size 28.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a3efb357502a6349d7dba3d67488966d09be66cac5c27ef8d4f8a5e51855cf72
BLAKE2b-256 checksum
How to use checksums
71ecd120aa779533c12376f3f431cdb7a50c0e04f11dc89c4acbaa8b12d6ad1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / datapy-0.2.0-py3-none-any.whl

Download URL datapy-0.2.0-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1baa0d4c06c2e38af583d493d858d0a36d5c33d5428bfa7169543bf3aeaf16c3
BLAKE2b-256 checksum
How to use checksums
4ea737025989371fcf14d4ecf1df41f4f9ba7bf600a8283f6693b58fa5211dd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for datapy 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for datapy-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page