Skip to main content

A minimal, type-safe, file-backed state tracker using Pydantic models.

Project description

simple-state-tracker

A minimal, file-backed, type-safe state tracker using Pydantic models — ideal for scripts, scrapers, ETL pipelines, and resumable workflows.

PyPI Python License

Features

  • 🧠 Strong typing with pydantic models
  • 💾 Transparent JSON persistence
  • 🧰 Simple .get(), .set(), .edit() API
  • ✅ Schema validation and strict key control
  • 🪶 Lightweight — no databases, no DAGs, no dependencies beyond pydantic

Installation

pip install simple-state-tracker

Example

## Quick Start

```python
from simple_state_tracker import SimpleStateTracker, KeyModel, DataModel

# First, define a key model
class ScrapeKey(KeyModel):
    county: str
    municipality: str
    year: int

# Next, define a data model
class ScrapeState(DataModel):
    scraped: bool = False
    scrape_error: str | None = None
    processed: bool = False
    process_error: str | None = None

# Initialize the tracker
tracker = SimpleStateTracker(ScrapeKey, ScrapeState, path="tracker.json")

key = ScrapeKey(county="DAUPHIN", municipality="HARRISBURG", year=2022)

with tracker.edit(key) as state:
    state.scraped = True
    state.scrape_error = None

tracker.save()

Use Cases

  • Track which URLs, files, or locations have been processed
  • Resume scraping jobs or ETL pipelines
  • Store structured state across CLI or batch job invocations
  • Replace ad-hoc JSON or YAML logs with something type-safe and self-validating

Non-Use Cases

Do not use this if

  • You are looking for optimization in storage or performance. This is meant to be easy to use and simple to understand, not the fastest or most efficient

API Overview

SimpleStateTracker(key_model, data_model, path)

Creates a new tracker instance.

  • get(key) → returns the data model (or None)
  • set(key, value) → manually sets a value
  • edit(key) → yields a context-managed editable state
  • save() → writes the cache to disk
  • load() → reads from disk
  • all() → returns a shallow copy of all state

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

simple_state_tracker-0.3.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_state_tracker-0.3.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file simple_state_tracker-0.3.1.tar.gz.

File metadata

  • Download URL: simple_state_tracker-0.3.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.0 Windows/11

File hashes

Hashes for simple_state_tracker-0.3.1.tar.gz
Algorithm Hash digest
SHA256 8dcdaa523160cc538463b797c98cc21e63df3ddbc9283d51111b608bbba08706
MD5 d4b468aa77af8e30e31e3e978fc48b34
BLAKE2b-256 fe5e736232760fa2cd72f1275384b865692cc187e05f613fd2eb5c38c15e1cfe

See more details on using hashes here.

File details

Details for the file simple_state_tracker-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_state_tracker-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1ccf75fc9af9b08d6c367ab8de60bc74ee4fb025ff22d7f5fcc15d769a2b4595
MD5 170b9d975ce342b69ece135a501fa67c
BLAKE2b-256 50c8c41431790690897e01bbfaa4792e4d0feed3c48e3c24c29fcaa17f407048

See more details on using hashes here.

Supported by

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