core package¶
Submodules¶
core.config module¶
core.db module¶
The db module handles database configuration and operations, including SQLAlchemy engine creation, session management, and database table creation and deletion.
- class core.db.Base(**kwargs: Any)¶
Bases:
DeclarativeBaseBase class for SQLAlchemy models.
- metadata: ClassVar[MetaData] = MetaData()¶
Refers to the
_schema.MetaDatacollection that will be used for new_schema.Tableobjects.See also
orm_declarative_metadata
- registry: ClassVar[_RegistryType] = <sqlalchemy.orm.decl_api.registry object>¶
Refers to the
_orm.registryin use where new_orm.Mapperobjects will be associated.
- async core.db.create_db_and_tables()¶
Create database tables based on SQLAlchemy models.
- async core.db.drop_db_and_tables()¶
Drop all database tables.
- async core.db.get_async_session() AsyncGenerator[AsyncSession, None]¶
Provide an asynchronous database session.
- Yield:
AsyncSession object.
core.fixtures module¶
core.router module¶
core.test_core module¶
core.utils module¶
The utils module provides utility functions for common operations such as string generation, path manipulation, header creation, and list processing.
- core.utils.get_jwt_header(jwt_token: str) dict¶
Create a JWT authorization header.
- Parameters:
jwt_token – JWT token string.
- Returns:
Dictionary containing the Authorization header.
- core.utils.is_sorted(lst, key=<function <lambda>>)¶
Check if a list is sorted based on a key function.
- Parameters:
lst – List to check.
key – Key function to determine sorting order. Default is identity function.
- Returns:
True if the list is sorted, False otherwise.
- core.utils.is_there_item(items: list, id) bool¶
Check if an item with a specific ID exists in a list.
- Parameters:
items – List of items (dictionaries with ‘id’ keys).
id – ID to search for.
- Returns:
True if the item exists, False otherwise.
- core.utils.path_with_id(router_path: str, id: int | UUID) str¶
Append an ID to a router path.
- Parameters:
router_path – Base router path.
id – ID to append (int or UUID).
- Returns:
Full path with the ID appended.
- core.utils.random_str(length: int = 8) str¶
Generate a random string of uppercase letters and digits.
- Parameters:
length – Length of the random string. Default is 8.
- Returns:
Randomly generated string.
- core.utils.x_www_form_urlencoded_header() str¶
Create a header for x-www-form-urlencoded content type.
- Returns:
Dictionary containing the Content-Type header.
Module contents¶
The core package contains the foundational modules and utilities for the backend application. It includes database setup, configuration, routing, and shared utilities.