Models¶
The models
module provides core data structures and types used throughout the application, following clean
architecture principles.
DTOs (Data Transfer Objects)¶
Base DTOs¶
Base classes for all DTOs with common functionality.
from archipy.models.dtos.base_dtos import BaseDTO
from pydantic import BaseModel
class UserDTO(BaseDTO):
id: str
username: str
email: str
created_at: datetime
archipy.models.dtos.base_dtos.BaseDTO
¶
Bases: BaseModel
Base Data Transfer Object class.
This class extends Pydantic's BaseModel to provide common configuration for all DTOs in the application.
Source code in archipy/models/dtos/base_dtos.py
options: show_root_heading: true show_source: true
Email DTOs¶
DTOs for email-related operations.
from archipy.models.dtos.email_dtos import EmailAttachmentDTO
attachment = EmailAttachmentDTO(
filename="document.pdf",
content_type="application/pdf",
content=b"..."
)
archipy.models.dtos.email_dtos.EmailAttachmentDTO
¶
Bases: BaseDTO
Pydantic model for email attachments.
Source code in archipy/models/dtos/email_dtos.py
archipy.models.dtos.email_dtos.EmailAttachmentDTO.set_content_type(v, values)
¶
Set content type based on filename extension if not provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
str | None
|
The content type value |
required |
values
|
dict
|
Other field values |
required |
Returns:
Type | Description |
---|---|
str | None
|
The determined content type or the original value |
Source code in archipy/models/dtos/email_dtos.py
archipy.models.dtos.email_dtos.EmailAttachmentDTO.validate_attachment_size(model)
¶
Validate that the attachment size does not exceed the maximum allowed size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Self
|
The model instance |
required |
Returns:
Type | Description |
---|---|
Self
|
The validated model instance |
Raises:
Type | Description |
---|---|
ValueError
|
If attachment size exceeds maximum allowed size |
Source code in archipy/models/dtos/email_dtos.py
archipy.models.dtos.email_dtos.EmailAttachmentDTO.validate_content_id(v, _)
¶
Ensure content_id is properly formatted with angle brackets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v
|
str | None
|
The content_id value |
required |
_
|
dict
|
Unused field values |
required |
Returns:
Type | Description |
---|---|
str | None
|
Properly formatted content_id |
Source code in archipy/models/dtos/email_dtos.py
options: show_root_heading: true show_source: true
Error DTOs¶
Standardized error response format.
from archipy.models.dtos.error_dto import ErrorDetailDTO
error = ErrorDetailDTO(
code="USER_NOT_FOUND",
message_en="User not found",
)
archipy.models.dtos.error_dto.ErrorDetailDTO
¶
Bases: BaseDTO
Standardized error detail model.
Source code in archipy/models/dtos/error_dto.py
archipy.models.dtos.error_dto.ErrorDetailDTO.create_error_detail(code, message_en, message_fa, http_status=None, grpc_status=None)
classmethod
¶
Creates an ErrorDetailDTO
with appropriate status codes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code
|
str
|
A unique error code. |
required |
message_en
|
str
|
The error message in English. |
required |
message_fa
|
str
|
The error message in Persian. |
required |
http_status
|
HTTPStatus | int | None
|
The HTTP status code associated with the error. |
None
|
grpc_status
|
StatusCode | int | None
|
The gRPC status code associated with the error. |
None
|
Returns:
Name | Type | Description |
---|---|---|
ErrorDetailDTO |
Self
|
The created exception detail object. |
Source code in archipy/models/dtos/error_dto.py
options: show_root_heading: true show_source: true
Pagination DTO¶
Handles pagination parameters for queries.
from archipy.models.dtos.pagination_dto import PaginationDTO
pagination = PaginationDTO(
page=1,
page_size=10,
total_items=100
)
archipy.models.dtos.pagination_dto.PaginationDTO
¶
Bases: BaseDTO
Data Transfer Object for pagination parameters.
This DTO encapsulates pagination information for database queries and API responses, providing a standard way to specify which subset of results to retrieve.
Attributes:
Name | Type | Description |
---|---|---|
page |
int
|
The current page number (1-based indexing) |
page_size |
int
|
Number of items per page |
offset |
int
|
Calculated offset for database queries based on page and page_size |
Examples:
>>> from archipy.models.dtos.pagination_dto import PaginationDTO
>>>
>>> # Default pagination (page 1, 10 items per page)
>>> pagination = PaginationDTO()
>>>
>>> # Custom pagination
>>> pagination = PaginationDTO(page=2, page_size=25)
>>> print(pagination.offset) # Access offset as a property
25
>>>
>>> # Using with a database query
>>> def get_users(pagination: PaginationDTO):
... query = select(User).offset(pagination.offset).limit(pagination.page_size)
... return db.execute(query).scalars().all()
Source code in archipy/models/dtos/pagination_dto.py
archipy.models.dtos.pagination_dto.PaginationDTO.offset
property
¶
Calculate the offset for database queries.
This property calculates how many records to skip based on the current page and page size.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The number of records to skip |
Examples:
archipy.models.dtos.pagination_dto.PaginationDTO.validate_pagination()
¶
Validate pagination limits to prevent excessive resource usage.
Ensures that the requested number of items (page * page_size) doesn't exceed the maximum allowed limit.
Returns:
Type | Description |
---|---|
Self
|
The validated model instance if valid. |
Raises:
Type | Description |
---|---|
OutOfRangeError
|
If the total requested items exceeds MAX_ITEMS. |
Source code in archipy/models/dtos/pagination_dto.py
options: show_root_heading: true show_source: true
Range DTOs¶
Handles range-based queries and filters.
from archipy.models.dtos.range_dtos import (
RangeDTO,
IntegerRangeDTO,
DateRangeDTO,
DatetimeRangeDTO
)
# Integer range
int_range = IntegerRangeDTO(start=1, end=100)
# Date range
date_range = DateRangeDTO(
start=date(2023, 1, 1),
end=date(2023, 12, 31)
)
# Datetime range
dt_range = DatetimeRangeDTO(
start=datetime(2023, 1, 1),
end=datetime(2023, 12, 31)
)
archipy.models.dtos.range_dtos.BaseRangeDTO
¶
Bases: BaseDTO
, Generic[R]
Base Data Transfer Object for range queries.
Encapsulates a range of values with from_ and to fields. Provides validation to ensure range integrity.
Source code in archipy/models/dtos/range_dtos.py
archipy.models.dtos.range_dtos.BaseRangeDTO.validate_range()
¶
Validate that from_ is less than or equal to to when both are provided.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The validated model instance. |
Raises:
Type | Description |
---|---|
OutOfRangeError
|
If from_ is greater than to. |
Source code in archipy/models/dtos/range_dtos.py
archipy.models.dtos.range_dtos.DecimalRangeDTO
¶
Bases: BaseRangeDTO[Decimal]
Data Transfer Object for decimal range queries.
Source code in archipy/models/dtos/range_dtos.py
archipy.models.dtos.range_dtos.DecimalRangeDTO.convert_to_decimal(value)
classmethod
¶
Convert input values to Decimal type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Decimal | str | None
|
The value to convert (None, string, or Decimal). |
required |
Returns:
Type | Description |
---|---|
Decimal | None
|
Decimal | None: The converted Decimal value or None. |
Raises:
Type | Description |
---|---|
InvalidArgumentError
|
If the value cannot be converted to Decimal. |
Source code in archipy/models/dtos/range_dtos.py
archipy.models.dtos.range_dtos.IntegerRangeDTO
¶
archipy.models.dtos.range_dtos.DateRangeDTO
¶
archipy.models.dtos.range_dtos.DatetimeRangeDTO
¶
Bases: BaseRangeDTO[datetime]
Data Transfer Object for datetime range queries.
Source code in archipy/models/dtos/range_dtos.py
archipy.models.dtos.range_dtos.DatetimeIntervalRangeDTO
¶
Bases: BaseRangeDTO[datetime]
Data Transfer Object for datetime range queries with interval.
Rejects requests if the number of intervals exceeds MAX_ITEMS or if interval-specific range size or 'to' age constraints are violated.
Source code in archipy/models/dtos/range_dtos.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
archipy.models.dtos.range_dtos.DatetimeIntervalRangeDTO.validate_interval_constraints()
¶
Validate interval based on range size, 'to' field age, and max intervals.
- Each interval has specific range size and 'to' age limits.
- Rejects if the number of intervals exceeds MAX_ITEMS.
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
The validated model instance. |
Raises:
Type | Description |
---|---|
OutOfRangeError
|
If interval constraints are violated or number of intervals > MAX_ITEMS. |
Source code in archipy/models/dtos/range_dtos.py
options: show_root_heading: true show_source: true
Search Input DTO¶
Standardized search parameters.
from archipy.models.dtos.search_input_dto import SearchInputDTO
search = SearchInputDTO[str](
query="john",
filters={"active": True},
pagination=pagination
)
archipy.models.dtos.search_input_dto.SearchInputDTO
¶
Bases: BaseModel
, Generic[T]
Data Transfer Object for search inputs with pagination and sorting.
This DTO encapsulates search parameters for database queries and API responses, providing a standard way to handle pagination and sorting.
Type Parameters
T: The type for sort column (usually an Enum with column names).
Source code in archipy/models/dtos/search_input_dto.py
options: show_root_heading: true show_source: true
Sort DTO¶
Handles sorting parameters for queries.
from archipy.models.dtos.sort_dto import SortDTO
sort = SortDTO[str](
field="created_at",
order="desc"
)
archipy.models.dtos.sort_dto.SortDTO
¶
Bases: BaseModel
, Generic[T]
Data Transfer Object for sorting parameters.
This DTO encapsulates sorting information for database queries and API responses, providing a standard way to specify how results should be ordered.
Attributes:
Name | Type | Description |
---|---|---|
column |
T | str
|
The name or enum value of the column to sort by |
order |
str
|
The sort direction - "ASC" for ascending, "DESC" for descending |
Examples:
>>> from archipy.models.dtos.sort_dto import SortDTO
>>> from archipy.models.types.sort_order_type import SortOrderType
>>>
>>> # Sort by name in ascending order
>>> sort = SortDTO(column="name", order=SortOrderType.ASCENDING)
>>>
>>> # Sort by creation date in descending order (newest first)
>>> sort = SortDTO(column="created_at", order="DESCENDING")
>>>
>>> # Using with a database query
>>> def get_sorted_users(sort: SortDTO = SortDTO.default()):
... query = select(User)
... if sort.order == SortOrderType.ASCENDING:
... query = query.order_by(getattr(User, sort.column).asc())
... else:
... query = query.order_by(getattr(User, sort.column).desc())
... return db.execute(query).scalars().all()
>>>
>>> # Using with enum column types
>>> from enum import Enum
>>> class UserColumns(Enum):
... ID = "id"
... NAME = "name"
... EMAIL = "email"
... CREATED_AT = "created_at"
>>>
>>> # Create a sort configuration with enum
>>> sort = SortDTO[UserColumns](column=UserColumns.NAME, order=SortOrderType.ASCENDING)
Source code in archipy/models/dtos/sort_dto.py
archipy.models.dtos.sort_dto.SortDTO.default()
classmethod
¶
Create a default sort configuration.
Returns a sort configuration that orders by created_at in descending order (newest first), which is a common default sorting behavior.
Returns:
Name | Type | Description |
---|---|---|
SortDTO |
SortDTO
|
A default sort configuration |
Examples:
>>> default_sort = SortDTO.default()
>>> print(f"Sort by {default_sort.column} {default_sort.order}")
Sort by created_at DESCENDING
Source code in archipy/models/dtos/sort_dto.py
options: show_root_heading: true show_source: true
Entities¶
SQLAlchemy Base Entities¶
Base classes for SQLAlchemy entities with various mixins for different capabilities.
from archipy.models.entities.sqlalchemy.base_entities import (
BaseEntity,
UpdatableEntity,
DeletableEntity,
AdminEntity,
ManagerEntity,
UpdatableDeletableEntity,
ArchivableEntity,
UpdatableAdminEntity,
UpdatableManagerEntity,
ArchivableDeletableEntity,
UpdatableDeletableAdminEntity,
UpdatableDeletableManagerEntity,
ArchivableAdminEntity,
ArchivableManagerEntity,
UpdatableManagerAdminEntity,
ArchivableManagerAdminEntity,
ArchivableDeletableAdminEntity,
ArchivableDeletableManagerEntity,
UpdatableDeletableManagerAdminEntity,
ArchivableDeletableManagerAdminEntity
)
from sqlalchemy import Column, String
# Basic entity
class User(BaseEntity):
__tablename__ = "users"
username = Column(String(100), unique=True)
email = Column(String(255), unique=True)
# Entity with update tracking
class Post(UpdatableEntity):
__tablename__ = "posts"
title = Column(String(200))
content = Column(String)
# Entity with soft deletion
class Comment(DeletableEntity):
__tablename__ = "comments"
text = Column(String)
# Entity with admin tracking
class AdminLog(AdminEntity):
__tablename__ = "admin_logs"
action = Column(String)
# Entity with manager tracking
class ManagerLog(ManagerEntity):
__tablename__ = "manager_logs"
action = Column(String)
archipy.models.entities.sqlalchemy.base_entities.BaseEntity
¶
Bases: DeclarativeBase
Base class for all SQLAlchemy models with automatic timestamps.
This class serves as the base for all entities in the application. It provides
common functionality such as automatic timestamping for created_at
and
validation for the primary key column.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.BaseEntity.__init_subclass__(**kw)
¶
Validate the subclass during initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kw
|
object
|
Additional keyword arguments passed to the subclass. |
{}
|
Raises:
Type | Description |
---|---|
AttributeError
|
If the subclass does not have the required primary key column. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.EntityAttributeChecker
¶
Utility class for validating model attributes.
This class provides functionality to ensure that at least one of the specified attributes is present in a model.
Attributes:
Name | Type | Description |
---|---|---|
required_any |
list[list[str]]
|
A list of lists, where each inner list contains attribute names. At least one attribute from each inner list must be present. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.EntityAttributeChecker.validate(base_class)
classmethod
¶
Validate that at least one of the required attributes is present.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_class
|
type
|
The class to validate. |
required |
Raises:
Type | Description |
---|---|
AttributeError
|
If none of the required attributes are present. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.DeletableMixin
¶
Mixin to add a deletable flag to models.
This mixin adds an is_deleted
column to indicate whether the entity has been
soft-deleted, allowing for logical deletion without physically removing records.
Attributes:
Name | Type | Description |
---|---|---|
is_deleted |
Flag indicating if the entity is deleted. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableMixin
¶
Mixin to add updatable timestamp functionality.
This mixin adds an updated_at
column to track the last update time of the entity,
automatically maintaining a timestamp of the most recent modification.
Attributes:
Name | Type | Description |
---|---|---|
updated_at |
Timestamp indicating when the entity was last updated. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ArchivableMixin
¶
Mixin to add Archivable functionality.
This mixin adds an is_archived
column to indicate whether the entity has been
archived, and an origin_uuid
column to reference the original entity.
Attributes:
Name | Type | Description |
---|---|---|
is_archived |
Flag indicating if the entity is archived. |
|
origin_uuid |
Reference to the original entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.AdminMixin
¶
Bases: EntityAttributeChecker
Mixin for models with admin-related attributes.
This mixin ensures that at least one of the admin-related attributes is present, providing tracking of which administrator created the entity.
Attributes:
Name | Type | Description |
---|---|---|
required_any |
list[list[str]]
|
Specifies the required admin-related attributes. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.AdminMixin.__init_subclass__(**kw)
¶
Validate the subclass during initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kw
|
object
|
Additional keyword arguments passed to the subclass. |
{}
|
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ManagerMixin
¶
Bases: EntityAttributeChecker
Mixin for models with manager-related attributes.
This mixin ensures that at least one of the manager-related attributes is present, providing tracking of which manager created the entity.
Attributes:
Name | Type | Description |
---|---|---|
required_any |
list[list[str]]
|
Specifies the required manager-related attributes. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ManagerMixin.__init_subclass__(**kw)
¶
Validate the subclass during initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kw
|
object
|
Additional keyword arguments passed to the subclass. |
{}
|
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableAdminMixin
¶
Bases: EntityAttributeChecker
Mixin for models updatable by admin.
This mixin ensures that at least one of the admin-related update attributes is present, providing tracking of which administrator last updated the entity.
Attributes:
Name | Type | Description |
---|---|---|
required_any |
list[list[str]]
|
Specifies the required admin-related update attributes. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableAdminMixin.__init_subclass__(**kw)
¶
Validate the subclass during initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kw
|
object
|
Additional keyword arguments passed to the subclass. |
{}
|
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableManagerMixin
¶
Bases: EntityAttributeChecker
Mixin for models updatable by managers.
This mixin ensures that at least one of the manager-related update attributes is present, providing tracking of which manager last updated the entity.
Attributes:
Name | Type | Description |
---|---|---|
required_any |
list[list[str]]
|
Specifies the required manager-related update attributes. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableManagerMixin.__init_subclass__(**kw)
¶
Validate the subclass during initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kw
|
object
|
Additional keyword arguments passed to the subclass. |
{}
|
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableEntity
¶
Bases: BaseEntity
, UpdatableMixin
Base class for entities that support updating timestamps.
This class extends BaseEntity with update tracking functionality, allowing applications to track when records were last modified.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.DeletableEntity
¶
Bases: BaseEntity
, DeletableMixin
Base class for entities that support soft deletion.
This class extends BaseEntity with soft deletion capability, allowing applications to mark records as deleted without physically removing them.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
is_deleted |
Flag indicating if the entity is deleted. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.AdminEntity
¶
Bases: BaseEntity
, AdminMixin
Base class for entities with admin-related attributes.
This class extends BaseEntity with tracking of which administrator created the entity, supporting audit and accountability requirements.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
created_by_admin/created_by_admin_uuid |
Mapped[datetime]
|
Reference to the admin who created the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ManagerEntity
¶
Bases: BaseEntity
, ManagerMixin
Base class for entities with manager-related attributes.
This class extends BaseEntity with tracking of which manager created the entity, supporting audit and accountability requirements.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
created_by/created_by_uuid |
Mapped[datetime]
|
Reference to the manager who created the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableDeletableEntity
¶
Bases: BaseEntity
, UpdatableMixin
, DeletableMixin
Base class for entities that support updating timestamps and soft deletion.
This class combines update tracking and soft deletion capabilities, providing a complete history of when records were created, updated, and deleted.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_deleted |
Flag indicating if the entity is deleted. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ArchivableEntity
¶
Bases: UpdatableEntity
, ArchivableMixin
Base class for entities that support archiving.
This class extends UpdatableEntity with archiving capability, allowing applications to mark records as archived and track the original entity.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_archived |
Flag indicating if the entity is archived. |
|
origin_uuid |
Reference to the original entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableAdminEntity
¶
Bases: BaseEntity
, UpdatableMixin
, AdminMixin
, UpdatableAdminMixin
Base class for entities updatable by admin with timestamps.
This class combines creation and update tracking for administrator actions, providing a comprehensive audit trail of administrative modifications.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
created_by_admin/created_by_admin_uuid |
Reference to the admin who created the entity. |
|
updated_by_admin/updated_by_admin_uuid |
Reference to the admin who last updated the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableManagerEntity
¶
Bases: BaseEntity
, UpdatableMixin
, ManagerMixin
, UpdatableManagerMixin
Base class for entities updatable by managers with timestamps.
This class combines creation and update tracking for manager actions, providing a comprehensive audit trail of management modifications.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
created_by/created_by_uuid |
Reference to the manager who created the entity. |
|
updated_by/updated_by_uuid |
Reference to the manager who last updated the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ArchivableDeletableEntity
¶
Bases: UpdatableDeletableEntity
, ArchivableMixin
Base class for entities that support both archiving and soft deletion.
This class combines archiving and soft deletion capabilities, providing a complete history of when records were created, updated, archived, and deleted.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_deleted |
Flag indicating if the entity is deleted. |
|
is_archived |
Flag indicating if the entity is archived. |
|
origin_uuid |
Reference to the original entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableDeletableAdminEntity
¶
Bases: BaseEntity
, UpdatableMixin
, AdminMixin
, UpdatableAdminMixin
, DeletableMixin
Base class for entities updatable by admin with timestamps and soft deletion.
This class combines administrator creation and update tracking with soft deletion, providing a complete audit trail throughout the entity's lifecycle.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_deleted |
Flag indicating if the entity is deleted. |
|
created_by_admin/created_by_admin_uuid |
Reference to the admin who created the entity. |
|
updated_by_admin/updated_by_admin_uuid |
Reference to the admin who last updated the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableDeletableManagerEntity
¶
Bases: BaseEntity
, UpdatableMixin
, ManagerMixin
, UpdatableManagerMixin
, DeletableMixin
Base class for entities updatable by managers with timestamps and soft deletion.
This class combines manager creation and update tracking with soft deletion, providing a complete audit trail throughout the entity's lifecycle.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_deleted |
Flag indicating if the entity is deleted. |
|
created_by/created_by_uuid |
Reference to the manager who created the entity. |
|
updated_by/updated_by_uuid |
Reference to the manager who last updated the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ArchivableAdminEntity
¶
Bases: ArchivableEntity
, AdminMixin
Base class for entities Archivable by admin.
This class extends ArchivableEntity with tracking of which administrator created the entity, supporting audit and accountability requirements.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_archived |
Flag indicating if the entity is archived. |
|
origin_uuid |
Reference to the original entity. |
|
created_by_admin/created_by_admin_uuid |
Reference to the admin who created the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ArchivableManagerEntity
¶
Bases: ArchivableEntity
, ManagerMixin
Base class for entities Archivable by managers.
This class extends ArchivableEntity with tracking of which manager created the entity, supporting audit and accountability requirements.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_archived |
Flag indicating if the entity is archived. |
|
origin_uuid |
Reference to the original entity. |
|
created_by/created_by_uuid |
Reference to the manager who created the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableManagerAdminEntity
¶
Bases: BaseEntity
, UpdatableMixin
, ManagerMixin
, AdminMixin
, UpdatableManagerMixin
, UpdatableAdminMixin
Base class for entities updatable by both managers and admins with timestamps.
This class provides comprehensive tracking of entity creation and updates by both administrators and managers, supporting complex workflows where different user roles interact with the same data.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
created_by_admin/created_by_admin_uuid |
Reference to the admin who created the entity. |
|
created_by/created_by_uuid |
Reference to the manager who created the entity. |
|
updated_by_admin/updated_by_admin_uuid |
Reference to the admin who last updated the entity. |
|
updated_by/updated_by_uuid |
Reference to the manager who last updated the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ArchivableManagerAdminEntity
¶
Bases: ArchivableEntity
, ManagerMixin
, AdminMixin
Base class for entities Archivable by both managers and admins.
This class provides comprehensive tracking of entity creation by both administrators and managers, supporting complex workflows where different user roles interact with the same data.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_archived |
Flag indicating if the entity is archived. |
|
origin_uuid |
Reference to the original entity. |
|
created_by_admin/created_by_admin_uuid |
Reference to the admin who created the entity. |
|
created_by/created_by_uuid |
Reference to the manager who created the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ArchivableDeletableAdminEntity
¶
Bases: ArchivableDeletableEntity
, AdminMixin
Base class for entities Archivable and deletable by admin.
This class combines administrator creation tracking with soft deletion and archiving, providing a complete audit trail throughout the entity's lifecycle.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_deleted |
Flag indicating if the entity is deleted. |
|
is_archived |
Flag indicating if the entity is archived. |
|
origin_uuid |
Reference to the original entity. |
|
created_by_admin/created_by_admin_uuid |
Reference to the admin who created the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ArchivableDeletableManagerEntity
¶
Bases: ArchivableDeletableEntity
, ManagerMixin
Base class for entities Archivable and deletable by managers.
This class combines manager creation tracking with soft deletion and archiving, providing a complete audit trail throughout the entity's lifecycle.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_deleted |
Flag indicating if the entity is deleted. |
|
is_archived |
Flag indicating if the entity is archived. |
|
origin_uuid |
Reference to the original entity. |
|
created_by/created_by_uuid |
Reference to the manager who created the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.UpdatableDeletableManagerAdminEntity
¶
Bases: BaseEntity
, UpdatableMixin
, ManagerMixin
, AdminMixin
, UpdatableManagerMixin
, UpdatableAdminMixin
, DeletableMixin
Base class for entities updatable by both managers and admins with timestamps and soft deletion.
This is the most comprehensive entity class, supporting tracking of creation and updates by both administrators and managers, along with soft deletion capability. It provides complete accountability for all operations throughout the entity's lifecycle.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_deleted |
Flag indicating if the entity is deleted. |
|
created_by_admin/created_by_admin_uuid |
Reference to the admin who created the entity. |
|
created_by/created_by_uuid |
Reference to the manager who created the entity. |
|
updated_by_admin/updated_by_admin_uuid |
Reference to the admin who last updated the entity. |
|
updated_by/updated_by_uuid |
Reference to the manager who last updated the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
archipy.models.entities.sqlalchemy.base_entities.ArchivableDeletableManagerAdminEntity
¶
Bases: ArchivableDeletableEntity
, ManagerMixin
, AdminMixin
Base class for entities Archivable and deletable by both managers and admins.
This is a comprehensive entity class, supporting tracking of creation by both administrators and managers, along with soft deletion and archiving capability. It provides complete accountability for all operations throughout the entity's lifecycle.
Attributes:
Name | Type | Description |
---|---|---|
created_at |
Mapped[datetime]
|
Timestamp indicating when the entity was created. |
updated_at |
Timestamp indicating when the entity was last updated. |
|
is_deleted |
Flag indicating if the entity is deleted. |
|
is_archived |
Flag indicating if the entity is archived. |
|
origin_uuid |
Reference to the original entity. |
|
created_by_admin/created_by_admin_uuid |
Reference to the admin who created the entity. |
|
created_by/created_by_uuid |
Reference to the manager who created the entity. |
Source code in archipy/models/entities/sqlalchemy/base_entities.py
options: show_root_heading: true show_source: true
Errors¶
The error handling system is organized into several categories, each handling specific types of errors:
Authentication Errors¶
Handles authentication and authorization related errors.
from archipy.models.errors import (
UnauthenticatedError,
InvalidCredentialsError,
TokenExpiredError,
InvalidTokenError,
SessionExpiredError,
PermissionDeniedError,
AccountLockedError,
AccountDisabledError,
InvalidVerificationCodeError
)
# Example: Handle invalid credentials
try:
authenticate_user(username, password)
except InvalidCredentialsError as e:
logger.warning(f"Failed login attempt: {e}")
Validation Errors¶
Handles input validation and format errors.
from archipy.models.errors import (
InvalidArgumentError,
InvalidFormatError,
InvalidEmailError,
InvalidPhoneNumberError,
InvalidLandlineNumberError,
InvalidNationalCodeError,
InvalidPasswordError,
InvalidDateError,
InvalidUrlError,
InvalidIpError,
InvalidJsonError,
InvalidTimestampError,
OutOfRangeError
)
# Example: Validate user input
try:
validate_user_input(email, phone)
except InvalidEmailError as e:
return {"error": e.to_dict()}
Resource Errors¶
Handles resource and data management errors.
from archipy.models.errors import (
NotFoundError,
AlreadyExistsError,
ConflictError,
ResourceLockedError,
ResourceBusyError,
DataLossError,
InvalidEntityTypeError,
FileTooLargeError,
InvalidFileTypeError,
QuotaExceededError
)
# Example: Handle resource not found
try:
user = get_user(user_id)
except NotFoundError as e:
return {"error": e.to_dict()}
Network Errors¶
Handles network and communication errors.
from archipy.models.errors import (
NetworkError,
ConnectionTimeoutError,
ServiceUnavailableError,
GatewayTimeoutError,
BadGatewayError,
RateLimitExceededError
)
# Example: Handle network issues
try:
response = make_api_request()
except ConnectionTimeoutError as e:
logger.error(f"Connection timeout: {e}")
Business Errors¶
Handles business logic and operation errors.
from archipy.models.errors import (
InvalidStateError,
BusinessRuleViolationError,
InvalidOperationError,
InsufficientFundsError,
InsufficientBalanceError,
MaintenanceModeError,
FailedPreconditionError
)
# Example: Handle business rule violation
try:
process_transaction(amount)
except InsufficientFundsError as e:
return {"error": e.to_dict()}
Database Errors¶
Handles database and storage related errors.
from archipy.models.errors import (
DatabaseConnectionError,
DatabaseQueryError,
DatabaseTransactionError,
StorageError,
CacheError,
CacheMissError
)
# Example: Handle database errors
try:
save_to_database(data)
except DatabaseConnectionError as e:
logger.error(f"Database connection failed: {e}")
System Errors¶
Handles system and internal errors.
from archipy.models.errors import (
InternalError,
ConfigurationError,
ResourceExhaustedError,
UnavailableError,
UnknownError,
AbortedError,
DeadlockDetectedError
)
# Example: Handle system errors
try:
process_request()
except DeadlockDetectedError as e:
logger.error(f"Deadlock detected: {e}")
# Implement retry logic
Error handling module for the application.
This module provides a comprehensive set of custom exceptions for handling various error scenarios in the application, organized by category.
archipy.models.errors.AccountDisabledError
¶
Bases: BaseError
Exception raised when an account is disabled.
Source code in archipy/models/errors/auth_errors.py
archipy.models.errors.AccountLockedError
¶
Bases: BaseError
Exception raised when an account is locked.
Source code in archipy/models/errors/auth_errors.py
archipy.models.errors.InvalidCredentialsError
¶
Bases: BaseError
Exception raised for invalid credentials.
Source code in archipy/models/errors/auth_errors.py
archipy.models.errors.InvalidTokenError
¶
Bases: BaseError
Exception raised when a token is invalid.
Source code in archipy/models/errors/auth_errors.py
archipy.models.errors.InvalidVerificationCodeError
¶
Bases: BaseError
Exception raised when a verification code is invalid.
Source code in archipy/models/errors/auth_errors.py
archipy.models.errors.PermissionDeniedError
¶
Bases: BaseError
Exception raised when permission is denied.
Source code in archipy/models/errors/auth_errors.py
archipy.models.errors.SessionExpiredError
¶
Bases: BaseError
Exception raised when a session has expired.
Source code in archipy/models/errors/auth_errors.py
archipy.models.errors.TokenExpiredError
¶
Bases: BaseError
Exception raised when a token has expired.
Source code in archipy/models/errors/auth_errors.py
archipy.models.errors.UnauthenticatedError
¶
Bases: BaseError
Exception raised when a user is unauthenticated.
Source code in archipy/models/errors/auth_errors.py
archipy.models.errors.BaseError
¶
Bases: Exception
Base exception class for all custom errors.
This class provides a standardized way to handle errors with support for: - Localization of error messages - Additional context data - Integration with HTTP and gRPC status codes
Attributes:
Name | Type | Description |
---|---|---|
error |
ErrorDetailDTO
|
The error details including message and status codes. |
lang |
LanguageType
|
The language for the error message. |
additional_data |
dict[str, Any] | None
|
Additional context data for the error. |
http_status_code |
ClassVar[int]
|
HTTP status code for the error. |
grpc_status_code |
ClassVar[int]
|
gRPC status code for the error. |
Source code in archipy/models/errors/base_error.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
archipy.models.errors.BaseError.http_status_code
property
¶
Gets the HTTP status code if HTTP support is available.
Returns:
Type | Description |
---|---|
int | None
|
Optional[int]: The HTTP status code or None if HTTP is not available. |
archipy.models.errors.BaseError.grpc_status_code
property
¶
Gets the gRPC status code if gRPC support is available.
Returns:
Type | Description |
---|---|
int | None
|
Optional[int]: The gRPC status code or None if gRPC is not available. |
archipy.models.errors.BaseError.code
property
¶
Gets the error code.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The error code. |
archipy.models.errors.BaseError.message
property
¶
Gets the current language message.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The error message in the current language. |
archipy.models.errors.BaseError.message_en
property
¶
Gets the English message.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The English error message. |
archipy.models.errors.BaseError.message_fa
property
¶
Gets the Persian message.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The Persian error message. |
archipy.models.errors.BaseError.__init__(error=None, lang=LanguageType.FA, additional_data=None, *args)
¶
Initialize the error with message and optional context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
error
|
ErrorDetailDTO | ErrorMessageType | None
|
The error detail or message. Can be: - ErrorDetail: Direct error detail object - ExceptionMessageType: Enum member containing error detail - None: Will use UNKNOWN_ERROR |
None
|
lang
|
LanguageType
|
Language code for the error message (defaults to Persian). |
FA
|
additional_data
|
dict | None
|
Additional context data for the error. |
None
|
*args
|
object
|
Additional arguments for the base Exception class. |
()
|
Source code in archipy/models/errors/base_error.py
archipy.models.errors.BaseError.get_message()
¶
Gets the localized error message based on the language setting.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The error message in the current language. |
Source code in archipy/models/errors/base_error.py
archipy.models.errors.BaseError.to_dict()
¶
Converts the exception to a dictionary format for API responses.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing error details and additional data. |
Source code in archipy/models/errors/base_error.py
archipy.models.errors.BaseError.__str__()
¶
String representation of the exception.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A formatted string containing the error code and message. |
archipy.models.errors.BaseError.__repr__()
¶
Detailed string representation of the exception.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A detailed string representation including all error details. |
Source code in archipy/models/errors/base_error.py
archipy.models.errors.BusinessRuleViolationError
¶
Bases: BaseError
Exception raised when a business rule is violated.
Source code in archipy/models/errors/business_errors.py
archipy.models.errors.FailedPreconditionError
¶
Bases: BaseError
Exception raised when a precondition for an operation is not met.
Source code in archipy/models/errors/business_errors.py
archipy.models.errors.InsufficientBalanceError
¶
Bases: BaseError
Exception raised when an operation fails due to insufficient account balance.
Source code in archipy/models/errors/business_errors.py
archipy.models.errors.InsufficientFundsError
¶
Bases: BaseError
Exception raised when there are insufficient funds for an operation.
Source code in archipy/models/errors/business_errors.py
archipy.models.errors.InvalidOperationError
¶
Bases: BaseError
Exception raised when an operation is not allowed in the current context.
Source code in archipy/models/errors/business_errors.py
archipy.models.errors.InvalidStateError
¶
Bases: BaseError
Exception raised when an operation is attempted in an invalid state.
Source code in archipy/models/errors/business_errors.py
archipy.models.errors.MaintenanceModeError
¶
Bases: BaseError
Exception raised when the system is in maintenance mode.
Source code in archipy/models/errors/business_errors.py
archipy.models.errors.CacheError
¶
Bases: BaseError
Exception raised for cache access errors.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.CacheMissError
¶
Bases: BaseError
Exception raised when requested data is not found in cache.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.DatabaseConfigurationError
¶
Bases: DatabaseError
Exception raised for database configuration errors.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.DatabaseConnectionError
¶
Bases: DatabaseError
Exception raised for database connection errors.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.DatabaseConstraintError
¶
Bases: DatabaseError
Exception raised for database constraint violations.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.DatabaseDeadlockError
¶
Bases: DatabaseError
Exception raised for database deadlock errors.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.DatabaseError
¶
Bases: BaseError
Base class for all database-related errors.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.DatabaseIntegrityError
¶
Bases: DatabaseError
Exception raised for database integrity violations.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.DatabaseQueryError
¶
Bases: DatabaseError
Exception raised for database query errors.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.DatabaseSerializationError
¶
Bases: DatabaseError
Exception raised for database serialization errors.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.DatabaseTimeoutError
¶
Bases: DatabaseError
Exception raised for database timeout errors.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.DatabaseTransactionError
¶
Bases: DatabaseError
Exception raised for database transaction errors.
Source code in archipy/models/errors/database_errors.py
archipy.models.errors.BadGatewayError
¶
Bases: BaseError
Exception raised when a gateway returns an invalid response.
Source code in archipy/models/errors/network_errors.py
archipy.models.errors.ConnectionTimeoutError
¶
Bases: BaseError
Exception raised when a connection times out.
Source code in archipy/models/errors/network_errors.py
archipy.models.errors.GatewayTimeoutError
¶
Bases: BaseError
Exception raised when a gateway times out.
Source code in archipy/models/errors/network_errors.py
archipy.models.errors.NetworkError
¶
Bases: BaseError
Exception raised for network-related errors.
Source code in archipy/models/errors/network_errors.py
archipy.models.errors.RateLimitExceededError
¶
Bases: BaseError
Exception raised when a rate limit is exceeded.
Source code in archipy/models/errors/network_errors.py
archipy.models.errors.ServiceUnavailableError
¶
Bases: BaseError
Exception raised when a service is unavailable.
Source code in archipy/models/errors/network_errors.py
archipy.models.errors.AlreadyExistsError
¶
Bases: BaseError
Exception raised when a resource already exists.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.ConflictError
¶
Bases: BaseError
Exception raised when there is a resource conflict.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.DataLossError
¶
Bases: BaseError
Exception raised when data is lost.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.FileTooLargeError
¶
Bases: BaseError
Exception raised when a file is too large.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.InvalidEntityTypeError
¶
Bases: BaseError
Exception raised for invalid entity types.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.InvalidFileTypeError
¶
Bases: BaseError
Exception raised for invalid file types.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.NotFoundError
¶
Bases: BaseError
Exception raised when a resource is not found.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.QuotaExceededError
¶
Bases: BaseError
Exception raised when a quota is exceeded.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.ResourceBusyError
¶
Bases: BaseError
Exception raised when a resource is busy.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.ResourceExhaustedError
¶
Bases: BaseError
Exception raised when a resource is exhausted.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.ResourceLockedError
¶
Bases: BaseError
Exception raised when a resource is locked.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.StorageError
¶
Bases: BaseError
Exception raised for storage-related errors.
Source code in archipy/models/errors/resource_errors.py
archipy.models.errors.AbortedError
¶
Bases: BaseError
Exception raised when an operation is aborted.
Source code in archipy/models/errors/system_errors.py
archipy.models.errors.ConfigurationError
¶
Bases: BaseError
Exception raised for system configuration errors.
Source code in archipy/models/errors/system_errors.py
archipy.models.errors.DeadlockDetectedError
¶
Bases: BaseError
Exception raised when a deadlock is detected in the system.
Source code in archipy/models/errors/system_errors.py
archipy.models.errors.InternalError
¶
Bases: BaseError
Exception raised for unexpected internal errors.
Source code in archipy/models/errors/system_errors.py
archipy.models.errors.UnavailableError
¶
Bases: BaseError
Exception raised when a requested service or feature is unavailable.
Source code in archipy/models/errors/system_errors.py
archipy.models.errors.UnknownError
¶
Bases: BaseError
Exception raised for unknown or unexpected error conditions.
Source code in archipy/models/errors/system_errors.py
archipy.models.errors.InvalidArgumentError
¶
Bases: BaseError
Exception raised for invalid arguments.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidDateError
¶
Bases: BaseError
Exception raised for invalid date formats.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidEmailError
¶
Bases: BaseError
Exception raised for invalid email formats.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidFormatError
¶
Bases: BaseError
Exception raised for invalid data formats.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidIpError
¶
Bases: BaseError
Exception raised for invalid IP address formats.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidJsonError
¶
Bases: BaseError
Exception raised for invalid JSON formats.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidLandlineNumberError
¶
Bases: BaseError
Exception raised for invalid landline numbers.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidNationalCodeError
¶
Bases: BaseError
Exception raised for invalid national codes.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidPasswordError
¶
Bases: BaseError
Exception raised when a password does not meet the security requirements.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidPhoneNumberError
¶
Bases: BaseError
Exception raised for invalid phone numbers.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidTimestampError
¶
Bases: BaseError
Exception raised when a timestamp format is invalid.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.InvalidUrlError
¶
Bases: BaseError
Exception raised for invalid URL formats.
Source code in archipy/models/errors/validation_errors.py
archipy.models.errors.OutOfRangeError
¶
Bases: BaseError
Exception raised when a value is out of range.
Source code in archipy/models/errors/validation_errors.py
options: show_root_heading: true show_source: true
Types¶
Base Types¶
Basic type definitions used throughout the application.
archipy.models.types.base_types.BaseType
¶
Bases: Enum
Base class for creating enumerated types with custom values.
This class extends the Enum
class to allow custom values for enum members.
Source code in archipy/models/types/base_types.py
archipy.models.types.base_types.BaseType.__new__(*args, **_)
¶
Create a new instance of the enum member.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cls
|
The enum class. |
required | |
*args
|
object
|
Arguments passed to the enum member. |
()
|
**_
|
object
|
Unused keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
BaseType |
BaseType
|
A new instance of the enum member with the custom value. |
Source code in archipy/models/types/base_types.py
archipy.models.types.base_types.FilterOperationType
¶
Bases: Enum
Enumeration of filter operations for querying or filtering data.
This enum defines the types of operations that can be used in filtering, such as equality checks, comparisons, and string matching.
Attributes:
Name | Type | Description |
---|---|---|
EQUAL |
str
|
Represents an equality check. |
NOT_EQUAL |
str
|
Represents a non-equality check. |
LESS_THAN |
str
|
Represents a less-than comparison. |
LESS_THAN_OR_EQUAL |
str
|
Represents a less-than-or-equal comparison. |
GREATER_THAN |
str
|
Represents a greater-than comparison. |
GREATER_THAN_OR_EQUAL |
str
|
Represents a greater-than-or-equal comparison. |
IN_LIST |
str
|
Represents a check for membership in a list. |
NOT_IN_LIST |
str
|
Represents a check for non-membership in a list. |
LIKE |
str
|
Represents a case-sensitive string pattern match. |
ILIKE |
str
|
Represents a case-insensitive string pattern match. |
STARTS_WITH |
str
|
Represents a check if a string starts with a given prefix. |
ENDS_WITH |
str
|
Represents a check if a string ends with a given suffix. |
CONTAINS |
str
|
Represents a check if a string contains a given substring. |
IS_NULL |
str
|
Represents a check if a value is null. |
IS_NOT_NULL |
str
|
Represents a check if a value is not null. |
Source code in archipy/models/types/base_types.py
options: show_root_heading: true show_source: true
Email Types¶
Type definitions for email-related operations.
archipy.models.types.email_types.EmailAttachmentType
¶
Bases: StrEnum
Enum representing different types of email attachments.
This enum defines the types of attachments that can be included in an email, such as files, base64-encoded data, URLs, or binary data.
Attributes:
Name | Type | Description |
---|---|---|
FILE |
str
|
Represents a file attachment. |
BASE64 |
str
|
Represents a base64-encoded attachment. |
URL |
str
|
Represents an attachment referenced by a URL. |
BINARY |
str
|
Represents raw binary data as an attachment. |
Source code in archipy/models/types/email_types.py
archipy.models.types.email_types.EmailAttachmentDispositionType
¶
Bases: StrEnum
Enum representing attachment disposition types.
This enum defines how an email attachment should be displayed or handled, such as being treated as a downloadable attachment or displayed inline.
Attributes:
Name | Type | Description |
---|---|---|
ATTACHMENT |
str
|
Represents an attachment that should be downloaded. |
INLINE |
str
|
Represents an attachment that should be displayed inline. |
Source code in archipy/models/types/email_types.py
options: show_root_heading: true show_source: true
Error Message Types¶
Standardized error message types for consistent error handling.
archipy.models.types.error_message_types.ErrorMessageType
¶
Bases: Enum
Enumeration of exception types with associated error details.
This class defines a set of standard exception types, each with an associated error code, English and Farsi messages, and corresponding HTTP and gRPC status codes.
Attributes:
Name | Type | Description |
---|---|---|
UNAUTHENTICATED |
Indicates that the user is not authenticated. |
|
INVALID_PHONE |
Indicates an invalid Iranian phone number. |
|
INVALID_LANDLINE |
Indicates an invalid Iranian landline number. |
|
INVALID_NATIONAL_CODE |
Indicates an invalid national code format. |
|
TOKEN_EXPIRED |
Indicates that the authentication token has expired. |
|
INVALID_TOKEN |
Indicates an invalid authentication token. |
|
PERMISSION_DENIED |
Indicates that the user does not have permission for the operation. |
|
NOT_FOUND |
Indicates that the requested resource was not found. |
|
ALREADY_EXISTS |
Indicates that the resource already exists. |
|
INVALID_ARGUMENT |
Indicates an invalid argument was provided. |
|
OUT_OF_RANGE |
Indicates that a value is out of the acceptable range. |
|
DEADLINE_EXCEEDED |
Indicates that the operation deadline was exceeded. |
|
FAILED_PRECONDITION |
Indicates that the operation preconditions were not met. |
|
RESOURCE_EXHAUSTED |
Indicates that the resource limit has been reached. |
|
ABORTED |
Indicates that the operation was aborted. |
|
CANCELLED |
Indicates that the operation was cancelled. |
|
INVALID_ENTITY_TYPE |
Indicates an invalid entity type. |
|
INTERNAL_ERROR |
Indicates an internal system error. |
|
DATA_LOSS |
Indicates critical data loss. |
|
UNIMPLEMENTED |
Indicates that the operation is not implemented. |
|
DEPRECATION |
Indicates that the operation is deprecated. |
|
UNAVAILABLE |
Indicates that the service is unavailable. |
|
UNKNOWN_ERROR |
Indicates an unknown error occurred. |
|
DEADLOCK |
Indicates a deadlock condition was detected. |
Source code in archipy/models/types/error_message_types.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 |
|
options: show_root_heading: true show_source: true
Language Type¶
Language code type definition.
archipy.models.types.language_type.LanguageType
¶
Bases: str
, Enum
Enum representing supported languages for error messages.
This enum defines the languages that are supported for generating or displaying error messages. Each language is represented by its ISO 639-1 code.
Attributes:
Name | Type | Description |
---|---|---|
FA |
str
|
Represents the Persian language (ISO 639-1 code: 'fa'). |
EN |
str
|
Represents the English language (ISO 639-1 code: 'en'). |
Source code in archipy/models/types/language_type.py
options: show_root_heading: true show_source: true
Sort Order Type¶
Sort order type definition for queries.
archipy.models.types.sort_order_type.SortOrderType
¶
Bases: Enum
Enumeration of sorting order types.
This enum defines the types of sorting orders that can be applied to data, such as ascending or descending.
Attributes:
Name | Type | Description |
---|---|---|
ASCENDING |
str
|
Represents sorting in ascending order. |
DESCENDING |
str
|
Represents sorting in descending order. |
Source code in archipy/models/types/sort_order_type.py
options: show_root_heading: true show_source: true
Key Classes¶
BaseDTO¶
Class: archipy.models.dtos.base_dtos.BaseDTO
Base class for all DTOs with features:
- Pydantic model inheritance
- JSON serialization
- Validation
- Type hints
- Common utility methods
BaseEntity¶
Class: archipy.models.entities.sqlalchemy.base_entities.BaseEntity
Base class for SQLAlchemy entities with features:
- UUID primary key
- Timestamp fields (created_at, updated_at)
- Common query methods
- Relationship support
- Type-safe column definitions
- Mixin support for:
- Update tracking
- Soft deletion
- Admin tracking
- Manager tracking
- Archiving
- Combined capabilities
BaseError¶
Class: archipy.models.errors.BaseError
Base class for custom errors with features:
- Standardized error format
- Error code system
- Detailed error messages
- Stack trace support
- Error context
- Additional data support
- Language localization
- HTTP and gRPC status code mapping