Reusable persistence and repository toolkit
Project description
persistence-kit
Reusable persistence toolkit with async repository implementations for:
memorymongo(Motor)postgres(SQLAlchemy async + asyncpg)
Documentation:
docs/repositories_and_relations.md
Author: Andres Felipe Serrano Barrios
Package Structure
persistence_kit is organized by responsibility:
contracts/: repository interfacessettings/: shared settings, parsers, and persistence constantsapi/: reusable API exceptions, handlers, and route loading helpersbootstrap/: startup helpers, configuration registry, and seed orchestrationutils/: transversal helpers such as upsert utilitiesrepository/: concrete repository implementations by backendrepository_factory/: entity registry, repository creation, and populated view repository
Recommended rule:
- import from
persistence_kitwhen the public facade is enough - import from the internal folders only when you need an implementation-specific module
Installation
pip install persistence-kit
Quick Start
from persistence_kit import Database
from persistence_kit.repository_factory import get_repo, register_entity
# register entities during application startup
register_entity(
"user",
{
"entity": User,
"collection": "users",
"database": Database.MEMORY,
"unique": {"email": "email"},
},
)
repo = get_repo("user")
Public API
Preferred public imports:
from persistence_kit import (
Repository,
ViewRepository,
RepoSettings,
Database,
ConfigRegistry,
configuration,
SeederProvider,
build_api_router,
handle_service_errors,
handle_repository_errors,
NotFoundException,
ValidationException,
BusinessRuleException,
DatabaseException,
)
from persistence_kit.repository_factory import (
register_entity,
get_repo,
get_repo_view,
provide_repo,
provide_view_repo,
set_registry_initializer,
)
Use internal paths only for implementation details, for example:
persistence_kit.repository.sqlalchemy_repo.sqlalchemy_repopersistence_kit.repository_factory.factory.repository_factorypersistence_kit.repository_factory.registry.entity_registrypersistence_kit.repository_factory.view.populating_repository
Typical Host Application Flow
- Define your entities as dataclasses.
- Register them in a local bootstrap such as
register_defaults. - Call
set_registry_initializer(register_defaults)during application startup. - Resolve repositories through
get_repo(...),get_repo_view(...), or FastAPI providers. - Use
ConfigRegistryandSeederProvideronly as shared bootstrap infrastructure. The concrete registrations remain in the host app.
Supported Environment Variables
REPO_DATABASE=memory|mongo|postgresMONGO_DSNMONGO_DBPOSTGRES_USERPOSTGRES_PASSWORDPOSTGRES_HOSTPOSTGRES_PORTPOSTGRES_DB
Local Development
Create the local environment and run tests from the library root:
poetry lock
poetry install --with dev
poetry run pytest -q
Current validation baseline:
persistence_kit:138 passed
Publish to PyPI (Manual)
python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*
python -m twine upload dist/*
Automated Publish via GitHub Actions
This repository includes a workflow at .github/workflows/publish-pypi.yml.
It publishes to PyPI when:
- a GitHub Release is published
- the release tag points to the current
mainHEAD
Prerequisite:
- Configure PyPI Trusted Publishing for this repository and workflow file.
Preview Releases Without PRs
Use .github/workflows/publish-preview.yml to publish directly from GitHub Actions
without merging a PR.
How it works:
- Trigger
Publish Preview Packagemanually from the Actions tab. - Enter a
version(for example0.1.1.dev1or0.1.2.dev1). - Choose target repository:
testpypi(recommended) orpypi. - The workflow patches
pyproject.tomlversion only inside the CI run, builds, and publishes. - No commit and no PR are required for this preview publish flow.
Important:
- Prefer
*.devNversions for preview builds. - PyPI/TestPyPI do not allow re-uploading the same file version.
Local Test Releases (No PR Required)
If you want to test changes from your machine in external projects without opening a PR, publish a prerelease from local code to TestPyPI.
1. Create a TestPyPI token
- Create an API token in TestPyPI.
- Export it as environment variable:
export TWINE_PASSWORD="pypi-***"
2. Publish from local code
bash ./scripts/publish-local.sh 0.1.1.dev1 testpypi
You can publish another local iteration with a new version:
bash ./scripts/publish-local.sh 0.1.1.dev2 testpypi
3. Install from external projects
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple persistence-kit==0.1.1.dev1
Recommended Release Strategy
- Local experimental testing: publish
0.x.y.devNto TestPyPI from local machine. - Official release: publish
0.x.yto PyPI through GitHub Release (publish-pypi.yml).
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
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 persistence_kit-1.0.0.tar.gz.
File metadata
- Download URL: persistence_kit-1.0.0.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63206e2a695b5368ea12854be3440723d35ab1ce36fb95b53bc71b5e852c15ac
|
|
| MD5 |
2703837769b259d3a99d58706d01e7e4
|
|
| BLAKE2b-256 |
70c65b88bec31e598cae1652233189b3f852fe0179b9dd3c10e7d927321d4b07
|
Provenance
The following attestation bundles were made for persistence_kit-1.0.0.tar.gz:
Publisher:
publish-pypi.yml on AndresFSerrano/persistence-kit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
persistence_kit-1.0.0.tar.gz -
Subject digest:
63206e2a695b5368ea12854be3440723d35ab1ce36fb95b53bc71b5e852c15ac - Sigstore transparency entry: 1088535743
- Sigstore integration time:
-
Permalink:
AndresFSerrano/persistence-kit@aa790d731a1972ce1dce02343ea1527a8676bc6c -
Branch / Tag:
refs/tags/v110 - Owner: https://github.com/AndresFSerrano
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@aa790d731a1972ce1dce02343ea1527a8676bc6c -
Trigger Event:
release
-
Statement type:
File details
Details for the file persistence_kit-1.0.0-py3-none-any.whl.
File metadata
- Download URL: persistence_kit-1.0.0-py3-none-any.whl
- Upload date:
- Size: 33.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
308592195c6a41ec1c6433633c49004b02ef65567684b4436fa6273d42385958
|
|
| MD5 |
1b0191c28dfc0c38a3c4596516de0f5c
|
|
| BLAKE2b-256 |
9b3f6b89388b378f3d1d6f00925c0b00cb81ab5d4460668744e0439525f63839
|
Provenance
The following attestation bundles were made for persistence_kit-1.0.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on AndresFSerrano/persistence-kit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
persistence_kit-1.0.0-py3-none-any.whl -
Subject digest:
308592195c6a41ec1c6433633c49004b02ef65567684b4436fa6273d42385958 - Sigstore transparency entry: 1088535773
- Sigstore integration time:
-
Permalink:
AndresFSerrano/persistence-kit@aa790d731a1972ce1dce02343ea1527a8676bc6c -
Branch / Tag:
refs/tags/v110 - Owner: https://github.com/AndresFSerrano
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@aa790d731a1972ce1dce02343ea1527a8676bc6c -
Trigger Event:
release
-
Statement type: