Skip to main content

Litebackup for Python

Back up, replicate, and restore SQLite databases with your Litebackup server and bucket. Python 3.11 or later on Linux or macOS.

pip install litebackup
export LITEBACKUP_API_KEY='JOIN_TOKEN@your-instance.litebackup.cloud'

LITEBACKUP_API_KEY is the value from Machines → Add machine, or an API key followed by @ and your server address. Wheels for Linux (glibc and musl) and macOS, on x64 and arm64, include the litebackup client, which the SDK starts on first use. On other platforms pip installs the source package, which uses an installed litebackup command: install it with curl -fsSL https://litebackup.com/cli.sh | bash, or set LITEBACKUP_PATH.

Back up an app's database

import os
import sqlite3

from litebackup import Litebackup

os.makedirs("data", exist_ok=True)
path = "data/app.sqlite"
connection = sqlite3.connect(path)
with Litebackup() as litebackup:
    rule = litebackup.backups.start(path)
    print(rule.id, rule.name)

Code that has the connection but not its path can ask SQLite which file it opened. database_path(connection) from litebackup.integrations.sqlite3 does this and raises invalid_argument for an in-memory database:

import os
import sqlite3

from litebackup import Litebackup

os.makedirs("data", exist_ok=True)
connection = sqlite3.connect("data/app.sqlite")
with Litebackup() as litebackup:
    (file,) = connection.execute("SELECT file FROM pragma_database_list WHERE name = 'main'").fetchone()
    if file:  # an empty file means in-memory: nothing to back up
        litebackup.backups.start(file)

backups.start returns once the daemon saved the rule; uploads run in the background. Call it on every start: the same path and settings return the saved rule, and other settings raise LitebackupError with code rule_exists and the saved rule in details["rule"].

Integration Extra Use
litebackup.integrations.sqlite3 database_path(connection, schema="main"), adapter()
litebackup.integrations.aiosqlite aiosqlite await database_path(connection), adapter()
litebackup.integrations.sqlalchemy sqlalchemy database_path(connection | engine | url), await async_database_path(async_connection | async_engine); for an engine with a custom creator, pass a connection
litebackup.integrations.django django Add to INSTALLED_APPS and set LITEBACKUP = {"databases": {"default": {}}}
litebackup.integrations.fastapi FastAPI(lifespan=backup_lifespan("/var/lib/app/main.sqlite"))
litebackup.release release find_release(metadata) verifies signed release metadata

Lease a database that moves between machines

from litebackup import Litebackup
from litebackup.integrations.sqlite3 import adapter

with Litebackup() as litebackup, litebackup.databases.pool(adapter=adapter()) as pool:
    with pool.lease("agents/42.sqlite", path="data/agents/42.sqlite", durability="server") as db:
        db.execute("CREATE TABLE IF NOT EXISTS steps (body TEXT)")
        db.execute("INSERT INTO steps (body) VALUES (?)", ("tests passed",))
        db.commit()

The first lease acquires the database's write lock, creating an empty file at path when nothing is there, and opens it. The pool keeps the lock and the open connection for later leases of the same name, which run one at a time, until no lease used it for idle_release (a minute by default; 0 keeps it), or you call pool.release(name) or pool.close(). Each release closes the connection and returns once your server has the final version.

Your app coordinates handovers between machines: while one machine keeps the lease, another machine's lease fails with lock_unavailable, or with lock_timeout=30 waits up to 30 seconds and succeeds once the first releases it. A lease on a database whose lock this machine lost meanwhile raises lock_lost before its block runs; the next lease acquires it again.

With durability="server" a lease returns once your server has what the block committed; "cloud" waits for the bucket too. The adapter opens existing files only and rolls back what the block did not commit; it never commits for you. A block that raises keeps the lease, and the release that ends it does not offload. A failed close does not release: the database stays acquired and the error is a LeaseCleanupError (lease_cleanup_failed). Several failures raise an ExceptionGroup.

For a database a backup rule on this machine covers, pool.use(name) yields its connection, bringing back an offloaded copy first and keeping it open between calls. A rollback-journal database under a rule saved with offload_rollback_journal is closed as soon as its last use block exits instead, so the rule never offloads it under an open connection.

asyncio

AsyncLitebackup has the same groups, awaited, and async iterators. The aiosqlite adapter below needs its extra: pip install 'litebackup[aiosqlite]'.

import asyncio

from litebackup import AsyncLitebackup
from litebackup.integrations.aiosqlite import adapter


async def main() -> None:
    async with AsyncLitebackup() as litebackup:
        async for database in litebackup.databases.all():
            print(database.name, database.state)
        async with (
            litebackup.databases.pool(adapter=adapter()) as pool,
            pool.lease("agents/42.sqlite", path="data/agents/42.sqlite") as db,
        ):
            await db.execute("CREATE TABLE IF NOT EXISTS steps (body TEXT)")
            await db.execute("INSERT INTO steps (body) VALUES (?)", ("tests passed",))
            await db.commit()


asyncio.run(main())

Cancelling a task stops its local wait; the daemon may still finish the operation, and asyncio.CancelledError propagates. A cancelled lease keeps the lock, and the release that ends it does not offload; a block that catches the cancellation and returns still counts as cancelled. close() waits for active blocks, and a cancelled close() keeps releasing; await it again to see its result.

Everything else

The groups are backups, rules, databases, replicas, events, session, and failovers, with keyword-only arguments. Durations are seconds or timedelta. Results are frozen dataclasses with the API's field names. close() never stops the daemon. See the SDK reference and integrations.

Metadata

Release files for litebackup 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for litebackup 1.2.0
File Size Uploaded Provenance Actions
litebackup-1.2.0.tar.gz 60.3 kB Without provenance Details for litebackup-1.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for litebackup 1.2.0
File Actions
litebackup-1.2.0-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details for litebackup-1.2.0-py3-none-musllinux_1_2_x86_64.whl
litebackup-1.2.0-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details for litebackup-1.2.0-py3-none-musllinux_1_2_aarch64.whl
litebackup-1.2.0-py3-none-manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for litebackup-1.2.0-py3-none-manylinux_2_17_x86_64.whl
litebackup-1.2.0-py3-none-manylinux_2_17_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for litebackup-1.2.0-py3-none-manylinux_2_17_aarch64.whl
litebackup-1.2.0-py3-none-macosx_13_0_x86_64.whl Python 3 none macOS 13.0+ x86-64 Details for litebackup-1.2.0-py3-none-macosx_13_0_x86_64.whl
litebackup-1.2.0-py3-none-macosx_13_0_arm64.whl Python 3 none macOS 13.0+ ARM64 Details for litebackup-1.2.0-py3-none-macosx_13_0_arm64.whl

Total release size: 102.0 MB

Release files / litebackup-1.2.0.tar.gz

Download URL litebackup-1.2.0.tar.gz
Size 60.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ffba8a1f40b10b2b8332342f376ef5cb95834e169cb928653eb0b6bfdcc9a8fb
BLAKE2b-256 checksum
How to use checksums
6dc57ba1337470971514b8344b482f260d61b054c69a1d997c5dbddb2c6defc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / litebackup-1.2.0-py3-none-musllinux_1_2_x86_64.whl

Download URL litebackup-1.2.0-py3-none-musllinux_1_2_x86_64.whl
Size 17.9 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
055b20c4d7a90e8a0973034ff86cb6f84efacf3e3e036b7306b1b39ad0fdbc4e
BLAKE2b-256 checksum
How to use checksums
729f85c86211f5e39f7cd3843c6db976d86ba038eaef6aa90843a88f77d6d912
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / litebackup-1.2.0-py3-none-musllinux_1_2_aarch64.whl

Download URL litebackup-1.2.0-py3-none-musllinux_1_2_aarch64.whl
Size 16.0 MB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
c8fdb9bfd0921eb86eff6503b30e90e95a04361f7fde4a5c0007c5db13ec1703
BLAKE2b-256 checksum
How to use checksums
f33212e6f07e49a3bedf565fe446a8b1a6a5dd5e8cb3cd8cd57ee76ff47b5ac7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / litebackup-1.2.0-py3-none-manylinux_2_17_x86_64.whl

Download URL litebackup-1.2.0-py3-none-manylinux_2_17_x86_64.whl
Size 17.9 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
baab8ab8738a00d85e45ea61a237bb3830705a37818a2e0e50f9016ee2c82a88
BLAKE2b-256 checksum
How to use checksums
0f8fb7c1cfb8fe21a076acaed2998517bd3fbccee4d83b6d5d2c4e88bf6dc754
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / litebackup-1.2.0-py3-none-manylinux_2_17_aarch64.whl

Download URL litebackup-1.2.0-py3-none-manylinux_2_17_aarch64.whl
Size 16.0 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
27f64aa3660ce20c06dc02e475a89ec96e94d635f4f979ca0084af91760011e1
BLAKE2b-256 checksum
How to use checksums
e77a38f3ce2e49a66bce174b5897cad16b2af1b319eaedd769661b67026d9656
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / litebackup-1.2.0-py3-none-macosx_13_0_x86_64.whl

Download URL litebackup-1.2.0-py3-none-macosx_13_0_x86_64.whl
Size 17.9 MB
Tags Python 3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
885c5239463b5d769b7f0b27e3a5d364762edd1c7a093db5b8ed07f12f7cce58
BLAKE2b-256 checksum
How to use checksums
e74aa6f4a463edd0d0c5909ec5e0270ef4f32370a82d88f96b41989588890048
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / litebackup-1.2.0-py3-none-macosx_13_0_arm64.whl

Download URL litebackup-1.2.0-py3-none-macosx_13_0_arm64.whl
Size 16.3 MB
Tags Python 3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
911e2ae37aa02570c08e0609ecf5088425856c700cc3ebed9023d5c4ae8d3c7f
BLAKE2b-256 checksum
How to use checksums
fe18c90daa34d7a3d9bf0cf2c15338b537d8c6e47de7a2782a70ebb834c61f72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for litebackup 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page