Skip to main content

Spilli-DBAL

Web-framework independent CRUD tools for working with database via SQLAlchemy.

Features

  • DBAL - database access layer.
  • CRUD methods for create, read, update and delete object from database.
  • Bulk methods for create, read, update and delete object from database.
  • Method of paginating data.
  • StatementMaker class for create query 'per-one-model'.
  • Marshmallow schemas for serialization input data for StatementMaker.
  • Marshmallow schemas for deserialization StatementMaker result object to dict.
  • Datetime with UTC timezone validation in BaseSchema.
  • Support for both synchronous and asynchronous (async/await) database operations.

Installation

Recommended using the latest version of Python. Spilli-DBAL supports Python 3.12 and newer.

Install and update using pip:

$ pip install -U spilli_dbal

Examples

Async example

import asyncio

from spilli_dbal.dbal import AsyncSqlaDBAL
from spilli_dbal.dbal.exceptions import DBALObjectNotFoundException
from spilli_dbal.models.base import ModelMixin
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column

engine = create_async_engine('sqlite+aiosqlite://', echo=False)
Base = declarative_base()


class Items(ModelMixin, Base):
    __tablename__ = 'items'
    data: Mapped[str] = mapped_column(comment='Data of item.')


class ItemsDBAL(AsyncSqlaDBAL[Items]):
    """Items DBAL."""


async def main() -> None:
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)

    async with AsyncSession(engine, expire_on_commit=False) as session:
        new_item = await ItemsDBAL(session).create(data='data')
        print('=>', 'New item:', new_item)

        item = await ItemsDBAL(session).read(id=new_item.id)
        print('=>', 'Item:', item)

        updated_item = await ItemsDBAL(session).update(id=new_item.id, data='updated_data')
        print('=>', 'Updated item:', updated_item)

        await ItemsDBAL(session).delete(id=new_item.id)
        try:
            await ItemsDBAL(session).read(id=new_item.id)
        except DBALObjectNotFoundException:
            print('=>', 'Deleted item.')

    await engine.dispose()


if __name__ == '__main__':
    asyncio.run(main())

Other examples in example/ folder.

Project automation

All commands are defined in the Makefile.

Builds the package, installs it from the sdist, and installs pre-commit hooks into git

make install

Run for build, install and test project.

make all

Metadata

Release files for Spilli-DBAL 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Spilli-DBAL 2.0.0
File Size Uploaded Provenance Actions
spilli_dbal-2.0.0.tar.gz 42.9 kB Without provenance Details for spilli_dbal-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Spilli-DBAL 2.0.0
File Interpreter ABI Platform Actions
spilli_dbal-2.0.0-py3-none-any.whl Python 3 none any Details for spilli_dbal-2.0.0-py3-none-any.whl

Total release size: 74.8 kB

Release files / spilli_dbal-2.0.0.tar.gz

Download URL spilli_dbal-2.0.0.tar.gz
Size 42.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9a8a1b6195b3a1d046f7bc9918b554f2499b7de2e24aca2da548ec6d91b7e3c9
BLAKE2b-256 checksum
How to use checksums
f617aacc23658b8f2abda96777163491ac41c0c13df29e2a421e4cbc22fb4121
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / spilli_dbal-2.0.0-py3-none-any.whl

Download URL spilli_dbal-2.0.0-py3-none-any.whl
Size 31.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
122ec698dc8195873568b7ab08d21517c6b56cf0e0742c4cf3a6b31383e9c631
BLAKE2b-256 checksum
How to use checksums
d6a7ebc9253e21fd01479b8ef43efcddad105c1b28d7752d65c67cdce11bc395
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for Spilli-DBAL 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page