Skip to main content

No project description provided

Project description

Welcome to s3sqlite-db

build status

This is an extension to encode/databases that allows using sqlite database with AWS S3. Main purpose for this is use with AWS Lambda, to download sqlite db to Lambda on db connect and upload back on disconnect.

Installation

$ pip install s3sqlite-db

Usage

You can use S3Database as async context manager:

S3_BUCKET = 'my-bucket'
S3_KEY = 'database.sqlite'
DATABASE_URL = f's3sqlite://{S3_BUCKET}/{S3_KEY}'

async with S3Database(DATABASE_URL) as db:
    query = table.select()
    db.fetch_all(query)

or with async framework like FastAPI:

from fastapi import FastAPI


app = FastAPI()
database = S3Database(DATABASE_URL)


@app.on_event("startup")
async def startup():
    await database.connect()

@app.on_event("shutdown")
async def shutdown():
    await database.disconnect()

Configuration

By default if remote database was modified, exception is raised, but ignote_conflicts=True argument can be specified, to force overwrite.

async with S3Database(DATABASE_URL, ignote_conflicts=True) as db:
    ...

Also you can specify a path to download local copy of db. This can be useful when working locally (not on AWS Lambda), or when whorking with several sqlite databaases at the same time.

async with S3Database(DATABASE_URL, local_path='/path/to/db.sqlite') as db:
    ...

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

s3sqlite-db-0.1.2.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

s3sqlite_db-0.1.2-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page