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 • 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
  1. 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.3.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.3-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: livecsv-0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 ef764c35762d78d63e56f53804c4d852f3547cec3a038ff02ed26e8d4273ca43
MD5 d0b591f0d0b9b0bb5926290dd695fe17
BLAKE2b-256 55450e0d77718e9cd418fc30eddde57ca18b661447e17923c32a05dba3eece43

See more details on using hashes here.

Provenance

The following attestation bundles were made for livecsv-0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: livecsv-0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 248336441f51682d975702991747414a4e7e59886cb1a7034503a04a228a5fb6
MD5 e6ad64e8ef0da586c9aa5ca110d80885
BLAKE2b-256 aadd56202048cdd639f35406976e5f9ac7237a28871739fa0eaff6624197cc87

See more details on using hashes here.

Provenance

The following attestation bundles were made for livecsv-0.3-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