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.4.tar.gz (8.3 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.4-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for livecsv-0.4.tar.gz
Algorithm Hash digest
SHA256 4ddc54d8861e992ec21a79b958936254c9ddca9a35a4224d41d8f70a6e7c0a17
MD5 b9889d2d84f4e6fb5f1546dae1cec86d
BLAKE2b-256 3c2d33e57c2cacc993c2501d5ce9a3130df9f05b1ea6336149ed2af1d3d9f0bd

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: livecsv-0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.6 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cbdf2fe7ea241cd231dd38e93b2942e31464af03858d063121066e4c2b190337
MD5 2c31844efaa1fe631d754faae18a711f
BLAKE2b-256 a01ec8d1427adee8c9f47487fe330bc4dee0c822f1f21a2c1e03cdbed2f190c1

See more details on using hashes here.

Provenance

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