Skip to main content

from typing import Self

UltraFramework

Description

Framework for FastAPI inspired by Java Spring.

  • It exposes a base entity class SQLEntity that can be derived in order to define custom entities.
  • It exposes a base repository class CRUDRepository[M] that can be derived in order to define custom repositories. The following public methods are available:
    • save(entity: M): M
    • save_many(entities: list[M]): list[M]
    • find_all(limit: int | None, offset: int | None): Iterable[M]
    • delete(entity: M): None

Example:

from typing import Self, Annotated

from sqlalchemy import create_engine, DDL
from sqlalchemy.orm import mapped_column, Mapped, Session
from sqlalchemy.sql.elements import ColumnElement
from ultra_framework.entities.sql_entity import SQLEntity
from ultra_framework.repositories.crud_repository import CRUDRepository
from ultra_framework.repositories.base_repository_factory import BaseRepositoryFactory
from ultra_framework.utils.dependencies import session_dependency
from ultra_framework.database.session_factory import SessionFactory


engine = create_engine("sqlite:///", connect_args={"check_same_thread": False})

conn = engine.connect()
conn.execute(DDL("""create table users (
    id integer primary key, 
    name text
)"""))
conn.close()

session_factory = SessionFactory(engine)


class UserEntity(SQLEntity):
  __tablename__ = "users"

  id: Mapped[int] = mapped_column(primary_key=True)
  name: Mapped[str]

  @classmethod
  def by_id(cls, idx: int) -> ColumnElement[bool]:
    return cls.id == idx


class UserRepository(CRUDRepository[UserEntity]):
  entity_class = UserEntity

  def find_by_id(self, idx: int) -> UserEntity:
    return self.filter_by_conditions([UserEntity.by_id(idx)]).one()


class RepositoryFactory(BaseRepositoryFactory):
  repository_map = {
    "users": UserRepository,
  }

  @property
  def user_repository(self) -> UserRepository:
    return self.get_repository("users")

  @classmethod
  def create_factory(cls, session: Annotated[Session, session_dependency(session_factory)]) -> Self:
    return cls(session)

Metadata

Release files for ultra-framework 1.0.0

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

Built distribution (wheel)

Table of built distributions (wheels) for ultra-framework 1.0.0
File Interpreter ABI Platform Actions
ultra_framework-1.0.0-py3-none-any.whl Python 3 none any Details for ultra_framework-1.0.0-py3-none-any.whl

Release files / ultra_framework-1.0.0-py3-none-any.whl

Download URL ultra_framework-1.0.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d9656a4c0f95796d0153681a3157135fa2f3b4914b855d1ffa631d8104f1f40
BLAKE2b-256 checksum
How to use checksums
b843f1a2be515e898875f904e0ba094f6bf8e939563abb6c27760524c98c6b53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for ultra-framework 1.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