Python function to query a SQLite file stored on S3
Project description
sqlite-s3-query
Python function to query a SQLite file stored on S3. It uses HTTP range requests to avoid downloading the entire database.
Work-in-progress. This README serves as a rough design spec.
Usage
import os
from sqlite_s3_query import sqlite_s3_query
results_iter = sqlite_s3_query(
'SELECT * FROM my_table ORDER BY my_column',
url='https://my-bucket.s3.eu-west-2.amazonaws.com/my-db.sqlite',
get_credentials=lambda: (
os.environ['AWS_DEFAULT_REGION'],
os.environ['AWS_ACCESS_KEY_ID'],
os.environ['AWS_SECRET_ACCESS_KEY'],
os.environ.get('AWS_SESSION_TOKEN'), # Only needed for temporary credentials
),
)
for row in results_iter:
print(row)
If in your project you use multiple queries to the same file, functools.partial
can be used to make an interface with less duplication.
from functools import partial
from sqlite_s3_query import sqlite_s3_query
query_my_db = partial(sqlite_s3_query,
url='https://my-bucket.s3.eu-west-2.amazonaws.com/my-db.sqlite',
get_credentials=lambda: (
os.environ['AWS_DEFAULT_REGION'],
os.environ['AWS_ACCESS_KEY_ID'],
os.environ['AWS_SECRET_ACCESS_KEY'],
os.environ.get('AWS_SESSION_TOKEN'), # Only needed for temporary credentials
),
)
for row in query_my_db('SELECT * FROM my_table_1 ORDER BY my_column'):
print(row)
for row in query_my_db('SELECT * FROM my_table_2 ORDER BY my_column'):
print(row)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sqlite-s3-query-0.0.0.tar.gz
(2.5 kB
view hashes)
Built Distribution
Close
Hashes for sqlite_s3_query-0.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ca6551879b38fd838b81b46c5b89bbfb4da1e7826483ad408d8f4a0fa804ee5 |
|
MD5 | dd3a5bff514c332c6ceda759bab21c72 |
|
BLAKE2b-256 | 8f691d3509d6acad9edadb47e2352e5d3f4b22ea658b7094c7e00cea7d9203f1 |