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
- Install pytest (if you haven’t already):
pip install pytest
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ddc54d8861e992ec21a79b958936254c9ddca9a35a4224d41d8f70a6e7c0a17
|
|
| MD5 |
b9889d2d84f4e6fb5f1546dae1cec86d
|
|
| BLAKE2b-256 |
3c2d33e57c2cacc993c2501d5ce9a3130df9f05b1ea6336149ed2af1d3d9f0bd
|
Provenance
The following attestation bundles were made for livecsv-0.4.tar.gz:
Publisher:
ci.yml on eyal-erknet/livecsv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
livecsv-0.4.tar.gz -
Subject digest:
4ddc54d8861e992ec21a79b958936254c9ddca9a35a4224d41d8f70a6e7c0a17 - Sigstore transparency entry: 170771310
- Sigstore integration time:
-
Permalink:
eyal-erknet/livecsv@96d8918eed3beddfdca5989d9cecee6f5a02b0ba -
Branch / Tag:
refs/tags/v0.4 - Owner: https://github.com/eyal-erknet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@96d8918eed3beddfdca5989d9cecee6f5a02b0ba -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbdf2fe7ea241cd231dd38e93b2942e31464af03858d063121066e4c2b190337
|
|
| MD5 |
2c31844efaa1fe631d754faae18a711f
|
|
| BLAKE2b-256 |
a01ec8d1427adee8c9f47487fe330bc4dee0c822f1f21a2c1e03cdbed2f190c1
|
Provenance
The following attestation bundles were made for livecsv-0.4-py3-none-any.whl:
Publisher:
ci.yml on eyal-erknet/livecsv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
livecsv-0.4-py3-none-any.whl -
Subject digest:
cbdf2fe7ea241cd231dd38e93b2942e31464af03858d063121066e4c2b190337 - Sigstore transparency entry: 170771312
- Sigstore integration time:
-
Permalink:
eyal-erknet/livecsv@96d8918eed3beddfdca5989d9cecee6f5a02b0ba -
Branch / Tag:
refs/tags/v0.4 - Owner: https://github.com/eyal-erknet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@96d8918eed3beddfdca5989d9cecee6f5a02b0ba -
Trigger Event:
push
-
Statement type: