Skip to main content

StateCrate

StateCrate adds backup and restore to Python applications. It puts selected files, directories, and consistent snapshots of live SQLite databases into one signed archive.

Before restoring anything, StateCrate checks the signer, every file, the archive layout, and each SQLite database. Unsafe paths, links, oversized archives, unexpected files, and damaged content are rejected.

StateCrate supports POSIX systems and Python 3.11 or newer.

Install

python -m pip install statecrate

Use

Create a signing key once and keep it somewhere separate from the backups:

from statecrate import SigningKey

key = SigningKey.generate()
key.save("backup-signing-key.pem")
key.verification_key.save("backup-public-key.pem")

Create a backup:

from statecrate import SigningKey, Source, backup

key = SigningKey.load("backup-signing-key.pem")

result = backup(
    "application-backup.tar.gz",
    [
        Source.file("config.json"),
        Source.directory("uploads"),
        Source.sqlite("application.db"),
    ],
    signing_key=key,
)

print(result.archive)

Check a backup without restoring it:

from statecrate import VerificationKey, verify

public_key = VerificationKey.load("backup-public-key.pem")
report = verify("application-backup.tar.gz", trusted_keys=public_key)
print(report.entries_checked)

Restore into a new directory:

from statecrate import restore

restore(
    "application-backup.tar.gz",
    "restored-state",
    trusted_keys=public_key,
)

Pass replace=True only when the destination is an application-state directory that StateCrate may replace completely. Unrelated files in that directory are not preserved.

What it handles

  • Live SQLite snapshots made through SQLite's backup API
  • Ed25519 manifest signatures and trusted-key selection
  • SHA-256 checks for every archived file
  • SQLite integrity checks before creation and after extraction
  • Safe paths, bounded extraction, and link rejection
  • Required and optional sources
  • File modes, empty directories, and custom JSON metadata
  • Staged creation, self-verification, durable writes, and rollback on a failed replacement

Boundaries

Archives are signed, but they are not encrypted. Anyone who can read an archive can read its contents. Encrypt the archive separately when confidentiality is required.

StateCrate creates and restores local archive files. Scheduling, retention, remote storage, incremental backups, and application-specific consistency are outside its scope.

Replacing an existing destination is rollback-safe when the process reports an error. POSIX does not provide a portable atomic exchange for non-empty directories, so a system failure between the two directory renames can require operator recovery from the hidden staging directory.

See the archive format for the compatibility and security contract.

Development

make install
make check

StateCrate is licensed under Apache License 2.0. Contributions are welcome; see CONTRIBUTING.md.

Metadata

Release files for statecrate 0.1.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 statecrate 0.1.0
File Size Uploaded
statecrate-0.1.0.tar.gz 30.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for statecrate 0.1.0
File Interpreter ABI Platform
statecrate-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.9 kB

Release files / statecrate-0.1.0.tar.gz

Download URL statecrate-0.1.0.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bab7db66757cbc678f9af8ede7643c3d761de34d753f180d31e66505995d4564
BLAKE2b-256 checksum
How to use checksums
0432951bee3b7cb8fc972e3f99995e989dc8ce8a9360f07e3a25858b74a37715
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

Release files / statecrate-0.1.0-py3-none-any.whl

Download URL statecrate-0.1.0-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a94287fb394ba64d300689707f4c2eb8c62b29659a586152ccd236c2be8c8b23
BLAKE2b-256 checksum
How to use checksums
2edefb43adc1220066e16231e20324655b7f671194328905ab716654695b4597
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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