Skip to main content

A custom SQLAlchemy dialect to load CSV from the web (using DuckDB for caching)

Project description

livecsv

livecsv is a custom SQLAlchemy dialect that loads CSV data from a remote source into an in‑memory DuckDB instance with caching support. It is designed for read‑only use and allows you to query CSV data as if it were a relational table.

Installation

Install livecsv using pip:

pip install livecsv

Dependencies

livecsv depends on the following packages: • SQLAlchemy (>=2.0.0) • duckdb • duckdb_engine

These dependencies will be automatically installed when you install livecsv.

Usage

The livecsv dialect lets you create a SQLAlchemy engine with a custom connection string that loads CSV data from a remote URL. The CSV is loaded into an in‑memory DuckDB instance, and the data is cached for a configurable number of minutes.

Connection String Format

The connection string format for livecsv is:

livecsv://<ssl_mode>/<cache_minutes>/<table_name>/<csv_url>

•	ssl_mode: Either secure (for HTTPS) or insecure (for HTTP).
•	cache_minutes: The number of minutes to cache the CSV data before refreshing. If 0, it is unlimited (not refreshed).
•	table_name: The name of the table that will be created in the in‑memory database.
•	csv_url: The URL to the CSV file (if the URL does not start with http, a scheme will be automatically prepended based on the ssl_mode).

Example

Below is a sample code snippet that demonstrates how to use livecsv:

from sqlalchemy import create_engine, text

Create an engine using the livecsv dialect.

engine = create_engine( "livecsv://secure/10/usernames/support.staffbase.com/hc/en-us/article_attachments/360009197031/username.csv" )

Query the table created from the CSV.

with engine.connect() as conn: result = conn.execute(text("SELECT * FROM usernames LIMIT 1")).fetchall() for row in result: print(row)

In this example, livecsv: • Loads the CSV from the specified URL. • Creates a table named usernames. • Caches the data for 10 minutes. • Allows you to query the data using SQLAlchemy.

Testing with pytest

livecsv includes tests that can be run using pytest.

Steps to Run Tests 1. Install pytest (if you haven’t already):

pip install pytest
2.	Run pytest

From the root of your project, run:

pytest

License

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

Author

Eyal Rahmani

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

livecsv-0.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

livecsv-0.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file livecsv-0.2.tar.gz.

File metadata

  • Download URL: livecsv-0.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for livecsv-0.2.tar.gz
Algorithm Hash digest
SHA256 cb12166626b548c7778d2db24c0b979408176c1bf6896e4ab0d5e13126b5c87e
MD5 b9e3876867425996dd49d3dfad081b62
BLAKE2b-256 809054ef55fcc2bba4f96aa4c53beadbeabe84a9afe43147b88acf9d1a666ec8

See more details on using hashes here.

Provenance

The following attestation bundles were made for livecsv-0.2.tar.gz:

Publisher: ci.yml on eyal-erknet/livecsv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file livecsv-0.2-py3-none-any.whl.

File metadata

  • Download URL: livecsv-0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for livecsv-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dd3a299018383145fb65b231e5311c2409fb8df877c07367aa8184d8844c601d
MD5 38231056522f3a246da66c06388bb4d9
BLAKE2b-256 3314f85a0a37e1f81878f1bd264d75c0af926442a027e00e14c28ffc4dfc430e

See more details on using hashes here.

Provenance

The following attestation bundles were made for livecsv-0.2-py3-none-any.whl:

Publisher: ci.yml on eyal-erknet/livecsv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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