Skip to main content

Run SQL-like queries on CSV files using a simple Python library or CLI.

Project description

csv-query

csv-query is a lightweight Python library and command-line tool that allows you to run SQL-like queries on CSV files easily. It’s designed for developers, analysts, and anyone who wants the power of SQL for CSV data without setting up a database.


Features

  • Simple SQL-like syntax: SELECT, WHERE, ORDER BY, LIMIT
  • Command-line interface (CLI) support
  • Save output as CSV or JSON
  • Pure Python + Pandas implementation
  • Works on any CSV file

Sample Usage (Python API)

from csv_query.core import query_csv

df = query_csv("employees.csv", "SELECT name, age WHERE department == 'HR' ORDER BY age DESC LIMIT 2")
print(df)

Sample Usage (CLI)

csv-query employees.csv "SELECT name, age WHERE age > 30 ORDER BY age DESC LIMIT 5"

To save output:

csv-query employees.csv "SELECT name, salary WHERE department == 'Engineering'" --output eng.csv
csv-query employees.csv "SELECT * ORDER BY age DESC LIMIT 3" --json top3.json

Installation

Install dependencies and install locally:

git clone https://github.com/your-username/csv-query.git
cd csv-query
pip install -e .

Command-Line Options

csv-query <file.csv> "<query>" [--output result.csv] [--json result.json]
Option Description
file.csv CSV file to query
"<query>" SQL-like query string
--output Save result as CSV
--json Save result as JSON

Supported Syntax

Basic SQL-like support:

  • SELECT column1, column2
  • WHERE condition (use pandas-style conditions)
  • ORDER BY column [ASC|DESC]
  • LIMIT N

Example: SELECT name, salary WHERE department == 'Finance' ORDER BY salary DESC LIMIT 3


Roadmap

  • SELECT, WHERE, ORDER BY, LIMIT
  • CLI with CSV/JSON export
  • Column aliasing (AS)
  • JOIN support
  • PyPI publishing
  • Unit testing with pytest

Author


License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

csvquerylite-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file csvquerylite-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: csvquerylite-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for csvquerylite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c2dff7172f3fa3bb38583c5775d92bab92a07d02865eda02e5e1f8ff06cb775
MD5 b3577a7c7ade78586ca67f399a3f471d
BLAKE2b-256 f00ad85ad0baad3a4958fdbe6d2057853ef7eb79ecd881dbdba48a1a25cc2158

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