Skip to main content

Framework based on FastAPI.

Project description

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
    • 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.commit()

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

  @CRUDRepository.auto_implement_one([UserEntity.by_id])
  def find_by_id(self, idx: int) -> UserEntity: ...


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)

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

ultra_framework-0.0.12.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

ultra_framework-0.0.12-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file ultra_framework-0.0.12.tar.gz.

File metadata

  • Download URL: ultra_framework-0.0.12.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ultra_framework-0.0.12.tar.gz
Algorithm Hash digest
SHA256 b72434a6603fc3ece50d3b612a41350dd8ee4f99daab5504376abcaeaf01c7ce
MD5 a977d12d0ed00a30d73c92f59e0a71aa
BLAKE2b-256 ddc1a6cd3ec93439f6dcec8c6b332d9c3ffddbf59baa679c5fef75a78a8d4d7f

See more details on using hashes here.

File details

Details for the file ultra_framework-0.0.12-py3-none-any.whl.

File metadata

File hashes

Hashes for ultra_framework-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 13c732c1f11c607f0d1b331559d0b7ac4c3df501c8ac27830a9eda6b0803fe26
MD5 49724b42b25c16fee524baba384a53d5
BLAKE2b-256 1536d971b1a73f2f611c9cc4681460862097fdf8f25e2a8450421c6a00f7fc8a

See more details on using hashes here.

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