Skip to main content

Data access layer for Spakky Framework (Repository implementations, ORM integration)

Project description

Spakky Data

Data access layer abstractions for Spakky Framework.

Installation

pip install spakky-data

Features

  • Repository Pattern: Generic repository interfaces for aggregate persistence
  • Transaction Management: Abstract transaction classes with autocommit support
  • External Proxy: Proxy pattern for external service data access

Quick Start

Repository Pattern

Define repository interfaces for your domain aggregates:

from abc import abstractmethod
from uuid import UUID

from spakky.data.persistency.repository import IAsyncGenericRepository
from spakky.domain.models.aggregate_root import AbstractAggregateRoot


class User(AbstractAggregateRoot[UUID]):
    name: str
    email: str


class IUserRepository(IAsyncGenericRepository[User, UUID]):
    @abstractmethod
    async def find_by_email(self, email: str) -> User | None: ...

Transaction Management

Use abstract transactions for database operations:

from spakky.data.persistency.transaction import AbstractAsyncTransaction


class SQLAlchemyTransaction(AbstractAsyncTransaction):
    def __init__(self, session_factory, autocommit: bool = True) -> None:
        super().__init__(autocommit)
        self.session_factory = session_factory
        self.session = None

    async def initialize(self) -> None:
        self.session = self.session_factory()

    async def dispose(self) -> None:
        await self.session.close()

    async def commit(self) -> None:
        await self.session.commit()

    async def rollback(self) -> None:
        await self.session.rollback()

Usage with context manager:

async with transaction:
    user = await repository.get(user_id)
    user.name = "New Name"
    await repository.save(user)
    # Automatically commits on success, rollbacks on exception

External Proxy Pattern

Access external service data with proxy interfaces:

from spakky.data.external.proxy import ProxyModel, IAsyncGenericProxy


class ExternalUser(ProxyModel[int]):
    name: str
    email: str


class IExternalUserProxy(IAsyncGenericProxy[ExternalUser, int]):
    pass

API Reference

Persistency

Class Description
IGenericRepository Sync generic repository interface
IAsyncGenericRepository Async generic repository interface
AbstractTransaction Sync transaction with context manager
AbstractAsyncTransaction Async transaction with context manager
EntityNotFoundError Raised when entity not found

External

Class Description
ProxyModel Base class for external service data models
IGenericProxy Sync proxy interface
IAsyncGenericProxy Async proxy interface

Errors

Class Description
AbstractSpakkyPersistencyError Base error for persistency operations
AbstractSpakkyExternalError Base error for external service operations

Related Packages

Package Description
spakky-domain DDD building blocks (Entity, AggregateRoot, ValueObject)
spakky-event Event publisher/consumer interfaces

License

MIT License

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

spakky_data-5.0.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.

spakky_data-5.0.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file spakky_data-5.0.0.tar.gz.

File metadata

  • Download URL: spakky_data-5.0.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spakky_data-5.0.0.tar.gz
Algorithm Hash digest
SHA256 88e1e89957cad4ac4dfa24df262309963947a6924e5cf0d4dfc25086394bd753
MD5 32a4acc9ec3cd496c7e1e0d2989b0feb
BLAKE2b-256 d08a22cc16ee054e7963213a31abbdc72e9074031d929697bedd1be1dfa6a180

See more details on using hashes here.

Provenance

The following attestation bundles were made for spakky_data-5.0.0.tar.gz:

Publisher: release.yml on E5presso/spakky-framework

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

File details

Details for the file spakky_data-5.0.0-py3-none-any.whl.

File metadata

  • Download URL: spakky_data-5.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spakky_data-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb4b062f6da5acbc62cac2ce8693fc7a0258f0423a431dafe4072d03ed0bbbea
MD5 186458176e77facb37e20c7568042a07
BLAKE2b-256 0c68b3a4d8a2d52b3daa1ce0555d46ea5ae5135162dd10086a1b72e51a35006a

See more details on using hashes here.

Provenance

The following attestation bundles were made for spakky_data-5.0.0-py3-none-any.whl:

Publisher: release.yml on E5presso/spakky-framework

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