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.41.tar.gz (8.0 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.41-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for livecsv-0.41.tar.gz
Algorithm Hash digest
SHA256 03bf83eddea26d5cb49e6d7cfa9bb610df470acad64e4aa871c29154bfb6f18a
MD5 1ee73c4cb7b0eedc4e49abf57e6fb3a3
BLAKE2b-256 15c621813c773d6c62dca761f23a566d1ac4505903e514a7d78c6d70f50ca468

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: livecsv-0.41-py3-none-any.whl
  • Upload date:
  • Size: 6.3 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.41-py3-none-any.whl
Algorithm Hash digest
SHA256 b3062333e11669694d15be6ef10bcf28c72c1174b867c9939e112ff926c61f25
MD5 78cdf05d7b25e51858624864edd428f1
BLAKE2b-256 7554a5cc133d17d64ebcc38eb71f5c9ef1af70b96b0f723b282689b9b0097fd7

See more details on using hashes here.

Provenance

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