Skip to main content

Infrastructure de base de données réutilisable pour les projets Baobab.

Project description

baobab-database

Infrastructure SQLite réutilisable pour les projets Baobab, basée sur SQLAlchemy 2.

Fonctionnalités

  • Registre de bases nommées (DatabaseRegistry, DatabaseSettings)
  • Factory de moteurs avec cache (EngineFactory)
  • Sessions et unité de travail transactionnelle (SessionFactory, UnitOfWork)
  • Création de schéma ORM (SchemaManager, Base)
  • Utilitaires SQLite : résolution de chemins, URL SQLAlchemy, pragmas WAL

Prérequis

  • Python 3.11 ou supérieur
  • pip

Installation

python -m venv .venv
# Windows
.\.venv\Scripts\Activate.ps1
# Linux / macOS
source .venv/bin/activate

pip install -e .
# avec outils de développement
pip install -e ".[dev]"

Démarrage rapide

from pathlib import Path

from baobab_database.config.database_registry import DatabaseRegistry
from baobab_database.config.database_settings import DatabaseSettings
from baobab_database.core.engine_factory import EngineFactory
from baobab_database.core.schema_manager import SchemaManager
from baobab_database.core.session_factory import SessionFactory
from baobab_database.core.unit_of_work import UnitOfWork
from baobab_database.sqlite.sqlite_path_resolver import SqlitePathResolver
from baobab_database.sqlite.sqlite_pragma_configurator import SqlitePragmaConfigurator
from baobab_database.sqlite.sqlite_url_factory import SqliteUrlFactory

registry = DatabaseRegistry(
    {
        "default": DatabaseSettings(
            name="default",
            database_path=Path("data/default.sqlite"),
        )
    }
)

engine_factory = EngineFactory(
    registry=registry,
    path_resolver=SqlitePathResolver(),
    url_factory=SqliteUrlFactory(),
    pragma_configurator=SqlitePragmaConfigurator(),
)

SchemaManager(engine_factory).create_schema("default")

session_factory = SessionFactory(engine_factory)
unit_of_work = UnitOfWork(session_factory)

with unit_of_work.begin("default") as session:
    # utiliser session ici
    pass

Structure du package

src/baobab_database/
├── config/          # DatabaseSettings, DatabaseRegistry
├── core/            # Base, EngineFactory, SessionFactory, UnitOfWork, SchemaManager
└── sqlite/          # SqlitePathResolver, SqliteUrlFactory, SqlitePragmaConfigurator

Qualité et tests

pytest
coverage run -m pytest && coverage report
black --check src tests
flake8 src tests
pylint src tests
mypy src tests
python -m bandit -r src/baobab_database

Seuil de couverture minimal du projet : 90 %.

Licence

MIT — voir le fichier de licence du dépôt.

Changelog

Voir CHANGELOG.md.

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

baobab_database-1.0.0.tar.gz (47.2 kB view details)

Uploaded Source

Built Distribution

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

baobab_database-1.0.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file baobab_database-1.0.0.tar.gz.

File metadata

  • Download URL: baobab_database-1.0.0.tar.gz
  • Upload date:
  • Size: 47.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for baobab_database-1.0.0.tar.gz
Algorithm Hash digest
SHA256 20f40a9aa4ff48b36108bc4348ce27cc62b98c7044b848feb1e60c09c3d62fa2
MD5 38e7169bb6537e6f44f895d9713bd2a5
BLAKE2b-256 9457f253f98af1145fa9bed4b088a19a4c4c0f1c1383e9378f696215097efa7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for baobab_database-1.0.0.tar.gz:

Publisher: release.yml on baobabgit/python-baobab-database

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file baobab_database-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: baobab_database-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for baobab_database-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dcf881b10b6bad20474ba04c603ecb080054489ddf2d4943ab643c827f01afe2
MD5 6019656deadac9b398c5255e9e2660db
BLAKE2b-256 4d7bac765533a6bc06dd2d6de99406964e848954639fb4f7232e377e61a9f688

See more details on using hashes here.

Provenance

The following attestation bundles were made for baobab_database-1.0.0-py3-none-any.whl:

Publisher: release.yml on baobabgit/python-baobab-database

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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