Skip to main content

A repository implementation for data persistence.

Project description

Data Persistence Repository

PyPI Build Status Coverage Status

Data Persistence Repository is a Python package providing a portable implementation of the repository pattern for a data persistence layer. For the moment there is only SQL support but it is planned to introduce more database types. This package facilitates interaction with SQL databases through an abstracted interface, ensuring clean and maintainable database interaction in Python applications.

Diagram

Features

  • Abstract repository interface for streamlined data layer interactions.
  • Async and sync SQL repository implementation with SQLAlchemy.
  • Context manager for robust database session management.
  • Methods for CRUD operations (Create, Read, Update, Delete).
  • Support for filtering and bulk operations.

Installation

Install Data Persistence Repository from PyPI:

pip install data_persistence_repository

Usage

Basic usage example (synchron):

from sqlalchemy.orm import Session
from data_persistence_repository.sql_repository import SqlRepository

class YourOwnRepository(SqlRepository):
    
    def special_query(self, session: Session):
        # execute a special query
        
# Initialize the repository
repo = YourOwnRepository("sqlite:///your_database.db")

# Use the repository within a managed context
with repo.start_session() as session:
    # Perform add, get, delete operations here
    repo.special_query(session)

Basic usage example (asynchron):

from sqlalchemy.ext.asyncio import AsyncSession
from data_persistence_repository.sql_repository_async import AsyncSqlRepository

class YourOwnRepository(AsyncSqlRepository):
    
    async def special_query(self, session: AsyncSession):
        # execute a special query
        await session.execute(...)

# Initialize the repository
repo = AsyncSqlRepository("sqlite:///your_database.db")

# Use the repository within a managed context
async with repo.start_session() as session:
    # Perform add, get, delete operations here
    await repo.special_query(session)

Replace "sqlite:///your_database.db" with your actual database URL.

Requirements

  • Python 3.x
  • Dependencies listed in requirements.txt.

Running Tests

Execute tests using pytest:

python -m pytest tests

Contributing

Contributions are welcomed! For substantial changes, please open an issue first to discuss what you'd like to change. Please make sure to update tests accordingly. Also, each PR must have tests.

License

MIT


For more information on the repository pattern and its benefits in data persistence, please visit Repository Design Pattern Information.

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

data_persistence_repository-0.2.3.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file data_persistence_repository-0.2.3.tar.gz.

File metadata

File hashes

Hashes for data_persistence_repository-0.2.3.tar.gz
Algorithm Hash digest
SHA256 1cc663c7f1b541e93f40141be555e9a688aba3c6a8ac32250d6bdf565def5f98
MD5 cc775776fb8195e0cc019adee789a697
BLAKE2b-256 ddf8769d97d41279ec91f52b3ca0de6f9e307aee53156d3754cd1417c05866f2

See more details on using hashes here.

File details

Details for the file data_persistence_repository-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for data_persistence_repository-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a40de22017e29217923a32a7058eaa2b0c485687beb7153990bfe7facb4840e9
MD5 c773e21a88b338deb7d89de7e984961b
BLAKE2b-256 8c5b0c10f13f282241945ce65872c742bbf86b52ed75316b80d6213f16b3dc3b

See more details on using hashes here.

Supported by

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