Skip to main content

thistle-db

Orbital element database manager. Ingests TLE (Two-Line Element) and OMM (Orbit Mean-Elements Message) files into a SQL database — the canonical, full-fidelity store — and maintains organized output files (TLE by object and by date; STK-compatible OMM CSV) rendered from the store after ingest.

Nothing is silently lost: records that fail validation are retained in a queryable rejects table with a reason code, and every run is recorded in an ingest_runs table (thistle-db status is the dashboard).

Installation

pip install thistle-db

# For MariaDB/MySQL support:
pip install thistle-db[mysql]

Or with uv:

uv add thistle-db

Quick Start

1. Scaffold configuration

thistle-db init

This creates two files:

  • ./config.toml -- main configuration (database, ingest sources, outputs)
  • ~/.config/thistle-db.toml -- user-local database credentials

Use -c to specify a different config path:

thistle-db -c /etc/thistle-db/config.toml init

2. Configure

Edit config.toml to set your database, ingest sources, and outputs. The generated file is fully commented — see example.config.toml for a complete operational layout.

SQLite (default; serverless):

[database]
drivername = "sqlite"
name = "thistle-db.db"

MariaDB/MySQL:

[database]
drivername = "mysql+pymysql"
host = "localhost"
port = 3306
name = "thistle-db"
secrets_file = "/etc/thistle-db/secrets.toml"

Then add your credentials to ~/.config/thistle-db.toml:

username = "myuser"
password = "mypassword"

Credentials never live in config.toml. Resolution order (highest priority first): THISTLE_DB_DATABASE__USERNAME/__PASSWORD env vars, the user secrets file, the system secrets file, config values.

3. Create the database schema

thistle-db init-db

Run once per database (idempotent — safe to re-run). Commands never create schema implicitly, so on MariaDB/PostgreSQL you can run init-db with an admin account and give the day-to-day account only read/write privileges. init-db --drop destroys and recreates everything (asks for confirmation unless --yes). For bulk restores, init-db --drop --defer-indexes creates the schema without the read-path indexes; a later plain init-db builds them in one fast sorted pass each.

4. Ingest

thistle-db ingest                      # scan configured source directories
thistle-db ingest 20260327.tle gp.json # or ingest specific files

Ingest is store-only and flushes per source file, so progress is durable file by file: a cancelled or killed run keeps every completed file's work, and the next run continues from the first unprocessed file. Output files are rendered afterwards — the steady-state cron entry is thistle-db ingest --update-outputs (or chain ingest and update-outputs). Outputs are optional: with no [[output.files]] entries, the deployment is store-only (useful when the database is queried directly, e.g. as thistle's catalog fallback).

File format is auto-detected by extension:

Extension Format
.tle, .txt, .3le Two-Line Element
.json Space-Track OMM JSON
.csv OMM CSV
.xml OMM XML

Ingestion is idempotent (duplicates are silently absorbed — the dedup key is the verbatim record text) and incremental (unchanged files are skipped without being opened). Validation is tolerant: one bad record never aborts a file, one bad file never aborts a scan.

Records that cannot be stored — unparseable text, non-finite mandatory elements, TLE checksum mismatches, epochs beyond the configurable future horizon, records with no NORAD ID — are retained in the rejects table with a reason code and provenance. Future-epoch rejects are re-admitted automatically once their epoch comes inside the horizon.

5. Outputs

Declared as [[output.files]] entries. thistle-db update-outputs re-renders exactly the files dirtied by records ingested since the last update (each file rendered whole from the store and replaced atomically — byte-identical to a rebuild of that file), and rebuild re-derives everything (first run, disaster recovery, or after adding/renaming an entry — which also initializes the entry's catch-up cursor):

  • Object files (type = "object") — all records for one satellite, epoch order. NORAD IDs render as integers (optionally zero-padded) or alpha-5; filenames are templatable (filename = "tle_{id}{ext}").
  • Date files (type = "date") — the latest record per satellite per epoch date.
  • Formats: tle (verbatim two-line passthrough — never a byte thistle synthesized) or omm-csv (the 17-column CelesTrak/STK projection, or columns = "full" for every store column).

Operations

thistle-db update-outputs    # render output files dirtied since last update
thistle-db status            # recent runs, reject trends, output lag, stuck runs
thistle-db verify            # reconcile outputs against the store (weekly cron)
thistle-db rejects           # summarize rejected input by reason
thistle-db rejects --export repair/   # write payloads out for repair + re-ingest
thistle-db get-tle 25544     # all TLEs for an object (alpha-5 IDs work too)
thistle-db get-tle 20260327  # nearest TLE per object to that date's noon
thistle-db export backup.csv # full-fidelity, re-ingestable backup
  • Runs are data: every ingest/update-outputs/rebuild writes an ingest_runs row with per-run counters; status reads it back (including how far outputs lag the store). Scans exit 0 even when individual files fail (they retry next scan); explicitly named files exit 1 on failure so cron wrappers can alert. An interrupted run finishes cancelled — its completed files are already durable.
  • Single-writer: the writing commands take an advisory lock beside the config file; a second writer exits immediately.
  • Bulk backfills: ingest everything (per-file flushes are cheap), then rebuild — with the whole catalog dirty, a scoped update would do the same work with worse streaming.
  • Backup/migration: export writes a full-fidelity CSV that re-ingests into any supported dialect (init-db + ingest backup.csv — also the schema-migration path; there is deliberately no migration framework). --format tle|omm-xml|omm-kvn cover legacy consumers and CCSDS OMM 2.0 interchange. Physical backups of a live server belong to the native tools.
  • Exit codes: 0 success; 1 runtime failure / no match; 2 invalid config or usage; 3 database not initialized.

Library use

from thistle_db import get_tles

pairs = get_tles(25544)   # [(line1, line2), ...] from the configured DB

thistle (the propagation package) uses this as its catalog fallback.

Supported databases

SQLite (default — dev, small and serverless deployments), MariaDB/MySQL (operational), PostgreSQL. Dialect-specific behavior is tested against all three in CI.

License

MIT

Metadata

Release files for thistle-db 0.17.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 thistle-db 0.17.0
File Size Uploaded Provenance Actions
thistle_db-0.17.0.tar.gz 93.7 kB Without provenance Details for thistle_db-0.17.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for thistle-db 0.17.0
File Interpreter ABI Platform Actions
thistle_db-0.17.0-py3-none-any.whl Python 3 none any Details for thistle_db-0.17.0-py3-none-any.whl

Total release size: 169.4 kB

Release files / thistle_db-0.17.0.tar.gz

Download URL thistle_db-0.17.0.tar.gz
Size 93.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9c6d22f10b2546d8f2e1a95c2c47b271d428c508b82f052aa77cb45766eafcd3
BLAKE2b-256 checksum
How to use checksums
a19a04fb0a265cac30595287fc52d23c80e50c7c0edf2a28d68b27c76e04c553
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / thistle_db-0.17.0-py3-none-any.whl

Download URL thistle_db-0.17.0-py3-none-any.whl
Size 75.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff31395b2bbd0a3a5f5bbed794195635cf82e9ec3751f5077efa64b7993384bb
BLAKE2b-256 checksum
How to use checksums
4ffee3515d37534f1cb6de6815c15920533fd88451dde8f4ca88748e80971ce9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for thistle-db 0.17.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