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

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.2.0.tar.gz (3.9 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.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_state_tracker-0.2.0.tar.gz
  • Upload date:
  • Size: 3.9 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.2.0.tar.gz
Algorithm Hash digest
SHA256 970e806877cbb7d0a92dc17301efa5baf6b699dfe22344278d7b02d2e83ae7fb
MD5 ad8b61aa084a1577b4ff0a832106f82e
BLAKE2b-256 4afe3662110da8facbd28b6529c0ca9f80f9e7cf4c03701bca54fb7f10d4c143

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_state_tracker-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5eb1412d3213d65c72cc048c170587783bea788e48f542d14d62869dc7cd1df
MD5 b7bac2b46f786142d425d3c59fcba60e
BLAKE2b-256 bcdf1e4962dfa62d71412f981daaf4d8b0be93c5d5fc731cc2b39f6458fac838

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