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.
Features
- 🧠 Strong typing with
pydanticmodels - 💾 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 (orNone)set(key, value)→ manually sets a valueedit(key)→ yields a context-managed editable statesave()→ writes the cache to diskload()→ reads from diskall()→ returns a shallow copy of all state
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_state_tracker-0.3.0.tar.gz.
File metadata
- Download URL: simple_state_tracker-0.3.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.0 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5627bcb59c65bfa4c9ffd3ff1d59db833c22a3849b49c0dca4eaea3e557c2e25
|
|
| MD5 |
6c89d708947f3fb877e8f769c6862872
|
|
| BLAKE2b-256 |
d347569b7ad80fcb20a5e4e38e1de5566ea812dabbbc65bc3ddcb69533e20784
|
File details
Details for the file simple_state_tracker-0.3.0-py3-none-any.whl.
File metadata
- Download URL: simple_state_tracker-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.0 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9698d055f7324c0c868f180ecbf5327572cde244ac99bd3d21b7db01f8fa6bd2
|
|
| MD5 |
7a5f01cb418d19b840e7538b035959ad
|
|
| BLAKE2b-256 |
82ac4ad28db974687fd8fd1ad747972e279a2d0c24199c91354962fc8ba503ee
|