Success Stories

Python success stories and case studies.

Module Contents

Success Stories domain.

class Story[source]

Bases: AuditBase, SlugMixin

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

category: Mapped[StoryCategory]
category_id: Mapped[UUID]
company_name: Mapped[str]
company_url: Mapped[str | None]
content: Mapped[str]
content_type: Mapped[ContentType]
created_at: Mapped[datetime.datetime]

Date/time of instance creation.

creator_id: Mapped[UUID]
featured: Mapped[bool]
id: Mapped[UUID]

UUID Primary key column.

image: Mapped[str | None]
is_published: Mapped[bool]
name: Mapped[str]
slug: Mapped[str]
updated_at: Mapped[datetime.datetime]

Date/time of instance last update.

class StoryCategory[source]

Bases: Base, NameSlugMixin

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

id: Mapped[UUID]

UUID Primary key column.

name: Mapped[str]
slug: Mapped[str]
stories: Mapped[list[Story]]
class StoryCategoryController[source]

Bases: Controller

Controller for StoryCategory CRUD operations.

after_request: AfterRequestHookHandler | None

A sync or async function executed before a Request is passed to any route handler.

If this function returns a value, the request will not reach the route handler, and instead this value will be used.

after_response: AfterResponseHookHandler | None

A sync or async function called after the response has been awaited.

It receives the Request instance and should not return any values.

before_request: BeforeRequestHookHandler | None

A sync or async function called immediately before calling the route handler.

It receives the Request instance and any non-None return value is used for the response, bypassing the route handler.

cache_control: CacheControlHeader | None

A CacheControlHeader header to add to route handlers of this controller.

Can be overridden by route handlers.

dependencies: Dependencies | None

A string keyed dictionary of dependency Provider instances.

dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for (de)serializing and validation of request data.

etag: ETag | None

An etag header of type ETag to add to route handlers of this controller.

Can be overridden by route handlers.

exception_handlers: ExceptionHandlersMap | None

A map of handler functions to status codes and/or exception types.

guards: Sequence[Guard] | None

A sequence of Guard callables.

include_in_schema: bool | EmptyType

A boolean flag dictating whether the route handler should be documented in the OpenAPI schema

middleware: Sequence[Middleware] | None

A sequence of Middleware.

opt: Mapping[str, Any] | None

A string key mapping of arbitrary values that can be accessed in Guards or wherever you have access to Request or ASGI Scope.

owner: Router

The Router or Litestar app that owns the controller.

This value is set internally by Litestar and it should not be set when subclassing the controller.

parameters: ParametersMap | None

A mapping of Parameter definitions available to all application paths.

path: str

A path fragment for the controller.

All route handlers under the controller will have the fragment appended to them. If not set it defaults to /.

request_class: type[Request] | None

A custom subclass of Request to be used as the default request for all route handlers under the controller.

request_max_body_size: int | None | EmptyType

Maximum allowed size of the request body in bytes. If this size is exceeded, a ‘413 - Request Entity Too Large’ error response is returned.

response_class: type[Response] | None

A custom subclass of Response to be used as the default response for all route handlers under the controller.

response_cookies: ResponseCookies | None

A list of Cookie instances.

response_headers: ResponseHeaders | None

A string keyed dictionary mapping ResponseHeader instances.

return_dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for serializing outbound response data.

security: Sequence[SecurityRequirement] | None

A sequence of dictionaries that to the schema of all route handlers under the controller.

signature_namespace: dict[str, Any]

A mapping of names to types for use in forward reference resolution during signature modelling.

signature_types: Sequence[Any]

A sequence of types for use in forward reference resolution during signature modelling.

These types will be added to the signature namespace using their __name__ attribute.

tags: Sequence[str] | None

A sequence of string tags that will be appended to the schema of all route handlers under the controller.

type_decoders: TypeDecodersSequence | None

A sequence of tuples, each composed of a predicate testing for type identity and a msgspec hook for deserialization.

type_encoders: TypeEncodersMap | None

A mapping of types to callables that transform them into types supported for serialization.

websocket_class: type[WebSocket] | None

A custom subclass of WebSocket to be used as the default websocket for all route handlers under the controller.

create_category(fn) = <litestar.handlers.http_handlers.decorators.post object>
delete_category(fn) = <litestar.handlers.http_handlers.decorators.delete object>
get_category(fn) = <litestar.handlers.http_handlers.decorators.get object>
get_category_by_slug(fn) = <litestar.handlers.http_handlers.decorators.get object>
list_categories(fn) = <litestar.handlers.http_handlers.decorators.get object>
update_category(fn) = <litestar.handlers.http_handlers.decorators.put object>
class StoryCategoryCreate[source]

Bases: StoryCategoryBase

Schema for creating a new StoryCategory.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class StoryCategoryRead[source]

Bases: StoryCategoryBase

Schema for reading StoryCategory data.

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: UUID
class StoryCategoryRepository[source]

Bases: SQLAlchemyAsyncRepository[StoryCategory]

Repository for StoryCategory database operations.

async get_by_slug(slug)[source]

Get a story category by slug.

Parameters:

slug (str) – The slug to search for.

Return type:

StoryCategory | None

Returns:

The story category if found, None otherwise.

model_type

alias of StoryCategory

class StoryCategoryService[source]

Bases: SQLAlchemyAsyncRepositoryService[StoryCategory, Any]

Service for StoryCategory business logic.

async get_by_slug(slug)[source]

Get a story category by slug.

Parameters:

slug (str) – The slug to search for.

Return type:

StoryCategory | None

Returns:

The story category if found, None otherwise.

match_fields: ClassVar[Optional[Union[list[str], str]]] = ['slug']

List of dialects that prefer to use field.id = ANY(:1) instead of field.id IN (...).

repository_type

alias of StoryCategoryRepository

class StoryCategoryUpdate[source]

Bases: BaseModel

Schema for updating a StoryCategory.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: Annotated[str, Field(min_length=1, max_length=200)] | None
class StoryController[source]

Bases: Controller

Controller for Story CRUD operations.

after_request: AfterRequestHookHandler | None

A sync or async function executed before a Request is passed to any route handler.

If this function returns a value, the request will not reach the route handler, and instead this value will be used.

after_response: AfterResponseHookHandler | None

A sync or async function called after the response has been awaited.

It receives the Request instance and should not return any values.

before_request: BeforeRequestHookHandler | None

A sync or async function called immediately before calling the route handler.

It receives the Request instance and any non-None return value is used for the response, bypassing the route handler.

cache_control: CacheControlHeader | None

A CacheControlHeader header to add to route handlers of this controller.

Can be overridden by route handlers.

dependencies: Dependencies | None

A string keyed dictionary of dependency Provider instances.

dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for (de)serializing and validation of request data.

etag: ETag | None

An etag header of type ETag to add to route handlers of this controller.

Can be overridden by route handlers.

exception_handlers: ExceptionHandlersMap | None

A map of handler functions to status codes and/or exception types.

guards: Sequence[Guard] | None

A sequence of Guard callables.

include_in_schema: bool | EmptyType

A boolean flag dictating whether the route handler should be documented in the OpenAPI schema

middleware: Sequence[Middleware] | None

A sequence of Middleware.

opt: Mapping[str, Any] | None

A string key mapping of arbitrary values that can be accessed in Guards or wherever you have access to Request or ASGI Scope.

owner: Router

The Router or Litestar app that owns the controller.

This value is set internally by Litestar and it should not be set when subclassing the controller.

parameters: ParametersMap | None

A mapping of Parameter definitions available to all application paths.

path: str

A path fragment for the controller.

All route handlers under the controller will have the fragment appended to them. If not set it defaults to /.

request_class: type[Request] | None

A custom subclass of Request to be used as the default request for all route handlers under the controller.

request_max_body_size: int | None | EmptyType

Maximum allowed size of the request body in bytes. If this size is exceeded, a ‘413 - Request Entity Too Large’ error response is returned.

response_class: type[Response] | None

A custom subclass of Response to be used as the default response for all route handlers under the controller.

response_cookies: ResponseCookies | None

A list of Cookie instances.

response_headers: ResponseHeaders | None

A string keyed dictionary mapping ResponseHeader instances.

return_dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for serializing outbound response data.

security: Sequence[SecurityRequirement] | None

A sequence of dictionaries that to the schema of all route handlers under the controller.

signature_namespace: dict[str, Any]

A mapping of names to types for use in forward reference resolution during signature modelling.

signature_types: Sequence[Any]

A sequence of types for use in forward reference resolution during signature modelling.

These types will be added to the signature namespace using their __name__ attribute.

tags: Sequence[str] | None

A sequence of string tags that will be appended to the schema of all route handlers under the controller.

type_decoders: TypeDecodersSequence | None

A sequence of tuples, each composed of a predicate testing for type identity and a msgspec hook for deserialization.

type_encoders: TypeEncodersMap | None

A mapping of types to callables that transform them into types supported for serialization.

websocket_class: type[WebSocket] | None

A custom subclass of WebSocket to be used as the default websocket for all route handlers under the controller.

create_story(fn) = <litestar.handlers.http_handlers.decorators.post object>
delete_story(fn) = <litestar.handlers.http_handlers.decorators.delete object>
get_story(fn) = <litestar.handlers.http_handlers.decorators.get object>
get_story_by_slug(fn) = <litestar.handlers.http_handlers.decorators.get object>
list_published_stories(fn) = <litestar.handlers.http_handlers.decorators.get object>
list_stories(fn) = <litestar.handlers.http_handlers.decorators.get object>
list_stories_by_category(fn) = <litestar.handlers.http_handlers.decorators.get object>
update_story(fn) = <litestar.handlers.http_handlers.decorators.put object>
class StoryCreate[source]

Bases: StoryBase

Schema for creating a new Story.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

category_id: UUID
creator_id: UUID
class StoryList[source]

Bases: BaseModel

Schema for Story list items.

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: UUID
slug: str
name: str
company_name: str
category_id: UUID
is_published: bool
featured: bool
image: str | None
created_at: datetime.datetime
class StoryRead[source]

Bases: StoryBase

Schema for reading Story data.

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: UUID
slug: str
category_id: UUID
creator_id: UUID
created_at: datetime.datetime
updated_at: datetime.datetime
class StoryRepository[source]

Bases: SQLAlchemyAsyncRepository[Story]

Repository for Story database operations.

async get_by_category_id(category_id, limit=100, offset=0)[source]

Get stories by category.

Parameters:
  • category_id (UUID) – The category ID to search for.

  • limit (int) – Maximum number of stories to return.

  • offset (int) – Number of stories to skip.

Return type:

list[Story]

Returns:

List of stories ordered by created_at descending.

async get_by_slug(slug)[source]

Get a story by slug.

Parameters:

slug (str) – The slug to search for.

Return type:

Story | None

Returns:

The story if found, None otherwise.

Get featured stories.

Parameters:

limit (int) – Maximum number of stories to return.

Return type:

list[Story]

Returns:

List of featured stories ordered by created_at descending.

async get_published_stories(limit=100, offset=0)[source]

Get published stories.

Parameters:
  • limit (int) – Maximum number of stories to return.

  • offset (int) – Number of stories to skip.

Return type:

list[Story]

Returns:

List of published stories ordered by created_at descending.

Get related stories from the same category.

Parameters:
  • story_id (UUID) – The story ID to exclude.

  • category_id (UUID) – The category ID to search for.

  • limit (int) – Maximum number of stories to return.

Return type:

list[Story]

Returns:

List of related stories ordered by created_at descending.

model_type

alias of Story

class StoryService[source]

Bases: SQLAlchemyAsyncRepositoryService[Story, Any]

Service for Story business logic.

async get_by_category_id(category_id, limit=100, offset=0)[source]

Get stories by category.

Parameters:
  • category_id (UUID) – The category ID to search for.

  • limit (int) – Maximum number of stories to return.

  • offset (int) – Number of stories to skip.

Return type:

list[Story]

Returns:

List of stories.

async get_by_slug(slug)[source]

Get a story by slug.

Parameters:

slug (str) – The slug to search for.

Return type:

Story | None

Returns:

The story if found, None otherwise.

Get featured stories.

Parameters:

limit (int) – Maximum number of stories to return.

Return type:

list[Story]

Returns:

List of featured stories.

async get_published_stories(limit=100, offset=0)[source]

Get published stories.

Parameters:
  • limit (int) – Maximum number of stories to return.

  • offset (int) – Number of stories to skip.

Return type:

list[Story]

Returns:

List of published stories.

Get related stories from the same category.

Parameters:
  • story_id (UUID) – The story ID to exclude.

  • category_id (UUID) – The category ID to search for.

  • limit (int) – Maximum number of stories to return.

Return type:

list[Story]

Returns:

List of related stories.

match_fields: ClassVar[Optional[Union[list[str], str]]] = ['slug']

List of dialects that prefer to use field.id = ANY(:1) instead of field.id IN (...).

repository_type

alias of StoryRepository

class StoryUpdate[source]

Bases: BaseModel

Schema for updating a Story.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: Annotated[str, Field(min_length=1, max_length=500)] | None
company_name: Annotated[str, Field(min_length=1, max_length=255)] | None
company_url: str | None
category_id: UUID | None
content: str | None
content_type: ContentType | None
is_published: bool | None
featured: bool | None
image: str | None
class StoryWithCategory[source]

Bases: StoryRead

Schema for Story with Category information.

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

category: StoryCategoryRead
class SuccessStoriesPageController[source]

Bases: Controller

Controller for success stories HTML pages.

after_request: AfterRequestHookHandler | None

A sync or async function executed before a Request is passed to any route handler.

If this function returns a value, the request will not reach the route handler, and instead this value will be used.

after_response: AfterResponseHookHandler | None

A sync or async function called after the response has been awaited.

It receives the Request instance and should not return any values.

before_request: BeforeRequestHookHandler | None

A sync or async function called immediately before calling the route handler.

It receives the Request instance and any non-None return value is used for the response, bypassing the route handler.

cache_control: CacheControlHeader | None

A CacheControlHeader header to add to route handlers of this controller.

Can be overridden by route handlers.

dependencies: Dependencies | None

A string keyed dictionary of dependency Provider instances.

dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for (de)serializing and validation of request data.

etag: ETag | None

An etag header of type ETag to add to route handlers of this controller.

Can be overridden by route handlers.

exception_handlers: ExceptionHandlersMap | None

A map of handler functions to status codes and/or exception types.

guards: Sequence[Guard] | None

A sequence of Guard callables.

include_in_schema: bool | EmptyType

A boolean flag dictating whether the route handler should be documented in the OpenAPI schema

middleware: Sequence[Middleware] | None

A sequence of Middleware.

opt: Mapping[str, Any] | None

A string key mapping of arbitrary values that can be accessed in Guards or wherever you have access to Request or ASGI Scope.

owner: Router

The Router or Litestar app that owns the controller.

This value is set internally by Litestar and it should not be set when subclassing the controller.

parameters: ParametersMap | None

A mapping of Parameter definitions available to all application paths.

path: str

A path fragment for the controller.

All route handlers under the controller will have the fragment appended to them. If not set it defaults to /.

request_class: type[Request] | None

A custom subclass of Request to be used as the default request for all route handlers under the controller.

request_max_body_size: int | None | EmptyType

Maximum allowed size of the request body in bytes. If this size is exceeded, a ‘413 - Request Entity Too Large’ error response is returned.

response_class: type[Response] | None

A custom subclass of Response to be used as the default response for all route handlers under the controller.

response_cookies: ResponseCookies | None

A list of Cookie instances.

response_headers: ResponseHeaders | None

A string keyed dictionary mapping ResponseHeader instances.

return_dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for serializing outbound response data.

security: Sequence[SecurityRequirement] | None

A sequence of dictionaries that to the schema of all route handlers under the controller.

signature_namespace: dict[str, Any]

A mapping of names to types for use in forward reference resolution during signature modelling.

signature_types: Sequence[Any]

A sequence of types for use in forward reference resolution during signature modelling.

These types will be added to the signature namespace using their __name__ attribute.

tags: Sequence[str] | None

A sequence of string tags that will be appended to the schema of all route handlers under the controller.

type_decoders: TypeDecodersSequence | None

A sequence of tuples, each composed of a predicate testing for type identity and a msgspec hook for deserialization.

type_encoders: TypeEncodersMap | None

A mapping of types to callables that transform them into types supported for serialization.

websocket_class: type[WebSocket] | None

A custom subclass of WebSocket to be used as the default websocket for all route handlers under the controller.

category_stories(fn) = <litestar.handlers.http_handlers.decorators.get object>
stories_index(fn) = <litestar.handlers.http_handlers.decorators.get object>
story_detail(fn) = <litestar.handlers.http_handlers.decorators.get object>
get_successstories_dependencies()[source]

Get all success stories domain dependency providers.

Return type:

dict

Models

Success Stories domain models.

class StoryCategory[source]

Bases: Base, NameSlugMixin

stories: Mapped[list[Story]]
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

id: Mapped[UUID]

UUID Primary key column.

name: Mapped[str]
slug: Mapped[str]
class Story[source]

Bases: AuditBase, SlugMixin

name: Mapped[str]
company_name: Mapped[str]
company_url: Mapped[str | None]
category_id: Mapped[UUID]
content: Mapped[str]
content_type: Mapped[ContentType]
is_published: Mapped[bool]
featured: Mapped[bool]
image: Mapped[str | None]
creator_id: Mapped[UUID]
category: Mapped[StoryCategory]
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

created_at: Mapped[datetime.datetime]

Date/time of instance creation.

id: Mapped[UUID]

UUID Primary key column.

slug: Mapped[str]
updated_at: Mapped[datetime.datetime]

Date/time of instance last update.

Schemas

Success Stories domain Pydantic schemas.

class StoryCategoryBase[source]

Bases: BaseModel

Base StoryCategory schema with common fields.

name: Annotated[str, Field(min_length=1, max_length=200)]
slug: Annotated[str, Field(min_length=1, max_length=200)]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class StoryCategoryCreate[source]

Bases: StoryCategoryBase

Schema for creating a new StoryCategory.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: Annotated[str, Field(min_length=1, max_length=200)]
slug: Annotated[str, Field(min_length=1, max_length=200)]
class StoryCategoryUpdate[source]

Bases: BaseModel

Schema for updating a StoryCategory.

name: Annotated[str, Field(min_length=1, max_length=200)] | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class StoryCategoryRead[source]

Bases: StoryCategoryBase

Schema for reading StoryCategory data.

id: UUID
model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: Annotated[str, Field(min_length=1, max_length=200)]
slug: Annotated[str, Field(min_length=1, max_length=200)]
class StoryBase[source]

Bases: BaseModel

Base Story schema with common fields.

name: Annotated[str, Field(min_length=1, max_length=500)]
company_name: Annotated[str, Field(min_length=1, max_length=255)]
company_url: str | None
content: str
content_type: ContentType
is_published: bool
featured: bool
image: str | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class StoryCreate[source]

Bases: StoryBase

Schema for creating a new Story.

category_id: UUID
creator_id: UUID
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: Annotated[str, Field(min_length=1, max_length=500)]
company_name: Annotated[str, Field(min_length=1, max_length=255)]
company_url: str | None
content: str
content_type: ContentType
is_published: bool
featured: bool
image: str | None
class StoryUpdate[source]

Bases: BaseModel

Schema for updating a Story.

name: Annotated[str, Field(min_length=1, max_length=500)] | None
company_name: Annotated[str, Field(min_length=1, max_length=255)] | None
company_url: str | None
category_id: UUID | None
content: str | None
content_type: ContentType | None
is_published: bool | None
featured: bool | None
image: str | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class StoryRead[source]

Bases: StoryBase

Schema for reading Story data.

id: UUID
slug: str
category_id: UUID
creator_id: UUID
created_at: datetime.datetime
updated_at: datetime.datetime
model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: Annotated[str, Field(min_length=1, max_length=500)]
company_name: Annotated[str, Field(min_length=1, max_length=255)]
company_url: str | None
content: str
content_type: ContentType
is_published: bool
featured: bool
image: str | None
class StoryList[source]

Bases: BaseModel

Schema for Story list items.

id: UUID
slug: str
name: str
company_name: str
category_id: UUID
is_published: bool
featured: bool
image: str | None
created_at: datetime.datetime
model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class StoryWithCategory[source]

Bases: StoryRead

Schema for Story with Category information.

category: StoryCategoryRead
model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: UUID
slug: str
category_id: UUID
creator_id: UUID
created_at: datetime.datetime
updated_at: datetime.datetime
name: Annotated[str, Field(min_length=1, max_length=500)]
company_name: Annotated[str, Field(min_length=1, max_length=255)]
company_url: str | None
content: str
content_type: ContentType
is_published: bool
featured: bool
image: str | None

Repositories

Success Stories domain repositories for database access.

class StoryCategoryRepository[source]

Bases: SQLAlchemyAsyncRepository[StoryCategory]

Repository for StoryCategory database operations.

model_type

alias of StoryCategory

async get_by_slug(slug)[source]

Get a story category by slug.

Parameters:

slug (str) – The slug to search for.

Return type:

StoryCategory | None

Returns:

The story category if found, None otherwise.

class StoryRepository[source]

Bases: SQLAlchemyAsyncRepository[Story]

Repository for Story database operations.

model_type

alias of Story

async get_by_slug(slug)[source]

Get a story by slug.

Parameters:

slug (str) – The slug to search for.

Return type:

Story | None

Returns:

The story if found, None otherwise.

async get_published_stories(limit=100, offset=0)[source]

Get published stories.

Parameters:
  • limit (int) – Maximum number of stories to return.

  • offset (int) – Number of stories to skip.

Return type:

list[Story]

Returns:

List of published stories ordered by created_at descending.

Get featured stories.

Parameters:

limit (int) – Maximum number of stories to return.

Return type:

list[Story]

Returns:

List of featured stories ordered by created_at descending.

async get_by_category_id(category_id, limit=100, offset=0)[source]

Get stories by category.

Parameters:
  • category_id (UUID) – The category ID to search for.

  • limit (int) – Maximum number of stories to return.

  • offset (int) – Number of stories to skip.

Return type:

list[Story]

Returns:

List of stories ordered by created_at descending.

Get related stories from the same category.

Parameters:
  • story_id (UUID) – The story ID to exclude.

  • category_id (UUID) – The category ID to search for.

  • limit (int) – Maximum number of stories to return.

Return type:

list[Story]

Returns:

List of related stories ordered by created_at descending.

Services

Success Stories domain services for business logic.

class StoryCategoryService[source]

Bases: SQLAlchemyAsyncRepositoryService[StoryCategory, Any]

Service for StoryCategory business logic.

repository_type

alias of StoryCategoryRepository

match_fields: ClassVar[Optional[Union[list[str], str]]] = ['slug']

List of dialects that prefer to use field.id = ANY(:1) instead of field.id IN (...).

async get_by_slug(slug)[source]

Get a story category by slug.

Parameters:

slug (str) – The slug to search for.

Return type:

StoryCategory | None

Returns:

The story category if found, None otherwise.

class StoryService[source]

Bases: SQLAlchemyAsyncRepositoryService[Story, Any]

Service for Story business logic.

repository_type

alias of StoryRepository

match_fields: ClassVar[Optional[Union[list[str], str]]] = ['slug']

List of dialects that prefer to use field.id = ANY(:1) instead of field.id IN (...).

async get_by_slug(slug)[source]

Get a story by slug.

Parameters:

slug (str) – The slug to search for.

Return type:

Story | None

Returns:

The story if found, None otherwise.

async get_published_stories(limit=100, offset=0)[source]

Get published stories.

Parameters:
  • limit (int) – Maximum number of stories to return.

  • offset (int) – Number of stories to skip.

Return type:

list[Story]

Returns:

List of published stories.

Get featured stories.

Parameters:

limit (int) – Maximum number of stories to return.

Return type:

list[Story]

Returns:

List of featured stories.

async get_by_category_id(category_id, limit=100, offset=0)[source]

Get stories by category.

Parameters:
  • category_id (UUID) – The category ID to search for.

  • limit (int) – Maximum number of stories to return.

  • offset (int) – Number of stories to skip.

Return type:

list[Story]

Returns:

List of stories.

Get related stories from the same category.

Parameters:
  • story_id (UUID) – The story ID to exclude.

  • category_id (UUID) – The category ID to search for.

  • limit (int) – Maximum number of stories to return.

Return type:

list[Story]

Returns:

List of related stories.

Controllers

Success Stories domain API and page controllers.

class StoryCategoryController[source]

Bases: Controller

Controller for StoryCategory CRUD operations.

path: str

A path fragment for the controller.

All route handlers under the controller will have the fragment appended to them. If not set it defaults to /.

tags: Sequence[str] | None

A sequence of string tags that will be appended to the schema of all route handlers under the controller.

list_categories(fn) = <litestar.handlers.http_handlers.decorators.get object>
get_category(fn) = <litestar.handlers.http_handlers.decorators.get object>
get_category_by_slug(fn) = <litestar.handlers.http_handlers.decorators.get object>
create_category(fn) = <litestar.handlers.http_handlers.decorators.post object>
update_category(fn) = <litestar.handlers.http_handlers.decorators.put object>
delete_category(fn) = <litestar.handlers.http_handlers.decorators.delete object>
after_request: AfterRequestHookHandler | None

A sync or async function executed before a Request is passed to any route handler.

If this function returns a value, the request will not reach the route handler, and instead this value will be used.

after_response: AfterResponseHookHandler | None

A sync or async function called after the response has been awaited.

It receives the Request instance and should not return any values.

before_request: BeforeRequestHookHandler | None

A sync or async function called immediately before calling the route handler.

It receives the Request instance and any non-None return value is used for the response, bypassing the route handler.

cache_control: CacheControlHeader | None

A CacheControlHeader header to add to route handlers of this controller.

Can be overridden by route handlers.

dependencies: Dependencies | None

A string keyed dictionary of dependency Provider instances.

dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for (de)serializing and validation of request data.

etag: ETag | None

An etag header of type ETag to add to route handlers of this controller.

Can be overridden by route handlers.

exception_handlers: ExceptionHandlersMap | None

A map of handler functions to status codes and/or exception types.

guards: Sequence[Guard] | None

A sequence of Guard callables.

include_in_schema: bool | EmptyType

A boolean flag dictating whether the route handler should be documented in the OpenAPI schema

middleware: Sequence[Middleware] | None

A sequence of Middleware.

opt: Mapping[str, Any] | None

A string key mapping of arbitrary values that can be accessed in Guards or wherever you have access to Request or ASGI Scope.

owner: Router

The Router or Litestar app that owns the controller.

This value is set internally by Litestar and it should not be set when subclassing the controller.

parameters: ParametersMap | None

A mapping of Parameter definitions available to all application paths.

request_class: type[Request] | None

A custom subclass of Request to be used as the default request for all route handlers under the controller.

request_max_body_size: int | None | EmptyType

Maximum allowed size of the request body in bytes. If this size is exceeded, a ‘413 - Request Entity Too Large’ error response is returned.

response_class: type[Response] | None

A custom subclass of Response to be used as the default response for all route handlers under the controller.

response_cookies: ResponseCookies | None

A list of Cookie instances.

response_headers: ResponseHeaders | None

A string keyed dictionary mapping ResponseHeader instances.

return_dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for serializing outbound response data.

security: Sequence[SecurityRequirement] | None

A sequence of dictionaries that to the schema of all route handlers under the controller.

signature_namespace: dict[str, Any]

A mapping of names to types for use in forward reference resolution during signature modelling.

signature_types: Sequence[Any]

A sequence of types for use in forward reference resolution during signature modelling.

These types will be added to the signature namespace using their __name__ attribute.

type_decoders: TypeDecodersSequence | None

A sequence of tuples, each composed of a predicate testing for type identity and a msgspec hook for deserialization.

type_encoders: TypeEncodersMap | None

A mapping of types to callables that transform them into types supported for serialization.

websocket_class: type[WebSocket] | None

A custom subclass of WebSocket to be used as the default websocket for all route handlers under the controller.

class StoryController[source]

Bases: Controller

Controller for Story CRUD operations.

path: str

A path fragment for the controller.

All route handlers under the controller will have the fragment appended to them. If not set it defaults to /.

tags: Sequence[str] | None

A sequence of string tags that will be appended to the schema of all route handlers under the controller.

list_stories(fn) = <litestar.handlers.http_handlers.decorators.get object>
get_story(fn) = <litestar.handlers.http_handlers.decorators.get object>
get_story_by_slug(fn) = <litestar.handlers.http_handlers.decorators.get object>
list_published_stories(fn) = <litestar.handlers.http_handlers.decorators.get object>
list_stories_by_category(fn) = <litestar.handlers.http_handlers.decorators.get object>
create_story(fn) = <litestar.handlers.http_handlers.decorators.post object>
update_story(fn) = <litestar.handlers.http_handlers.decorators.put object>
delete_story(fn) = <litestar.handlers.http_handlers.decorators.delete object>
after_request: AfterRequestHookHandler | None

A sync or async function executed before a Request is passed to any route handler.

If this function returns a value, the request will not reach the route handler, and instead this value will be used.

after_response: AfterResponseHookHandler | None

A sync or async function called after the response has been awaited.

It receives the Request instance and should not return any values.

before_request: BeforeRequestHookHandler | None

A sync or async function called immediately before calling the route handler.

It receives the Request instance and any non-None return value is used for the response, bypassing the route handler.

cache_control: CacheControlHeader | None

A CacheControlHeader header to add to route handlers of this controller.

Can be overridden by route handlers.

dependencies: Dependencies | None

A string keyed dictionary of dependency Provider instances.

dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for (de)serializing and validation of request data.

etag: ETag | None

An etag header of type ETag to add to route handlers of this controller.

Can be overridden by route handlers.

exception_handlers: ExceptionHandlersMap | None

A map of handler functions to status codes and/or exception types.

guards: Sequence[Guard] | None

A sequence of Guard callables.

include_in_schema: bool | EmptyType

A boolean flag dictating whether the route handler should be documented in the OpenAPI schema

middleware: Sequence[Middleware] | None

A sequence of Middleware.

opt: Mapping[str, Any] | None

A string key mapping of arbitrary values that can be accessed in Guards or wherever you have access to Request or ASGI Scope.

owner: Router

The Router or Litestar app that owns the controller.

This value is set internally by Litestar and it should not be set when subclassing the controller.

parameters: ParametersMap | None

A mapping of Parameter definitions available to all application paths.

request_class: type[Request] | None

A custom subclass of Request to be used as the default request for all route handlers under the controller.

request_max_body_size: int | None | EmptyType

Maximum allowed size of the request body in bytes. If this size is exceeded, a ‘413 - Request Entity Too Large’ error response is returned.

response_class: type[Response] | None

A custom subclass of Response to be used as the default response for all route handlers under the controller.

response_cookies: ResponseCookies | None

A list of Cookie instances.

response_headers: ResponseHeaders | None

A string keyed dictionary mapping ResponseHeader instances.

return_dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for serializing outbound response data.

security: Sequence[SecurityRequirement] | None

A sequence of dictionaries that to the schema of all route handlers under the controller.

signature_namespace: dict[str, Any]

A mapping of names to types for use in forward reference resolution during signature modelling.

signature_types: Sequence[Any]

A sequence of types for use in forward reference resolution during signature modelling.

These types will be added to the signature namespace using their __name__ attribute.

type_decoders: TypeDecodersSequence | None

A sequence of tuples, each composed of a predicate testing for type identity and a msgspec hook for deserialization.

type_encoders: TypeEncodersMap | None

A mapping of types to callables that transform them into types supported for serialization.

websocket_class: type[WebSocket] | None

A custom subclass of WebSocket to be used as the default websocket for all route handlers under the controller.

class SuccessStoriesPageController[source]

Bases: Controller

Controller for success stories HTML pages.

path: str

A path fragment for the controller.

All route handlers under the controller will have the fragment appended to them. If not set it defaults to /.

include_in_schema: bool | EmptyType

A boolean flag dictating whether the route handler should be documented in the OpenAPI schema

stories_index(fn) = <litestar.handlers.http_handlers.decorators.get object>
story_detail(fn) = <litestar.handlers.http_handlers.decorators.get object>
category_stories(fn) = <litestar.handlers.http_handlers.decorators.get object>
after_request: AfterRequestHookHandler | None

A sync or async function executed before a Request is passed to any route handler.

If this function returns a value, the request will not reach the route handler, and instead this value will be used.

after_response: AfterResponseHookHandler | None

A sync or async function called after the response has been awaited.

It receives the Request instance and should not return any values.

before_request: BeforeRequestHookHandler | None

A sync or async function called immediately before calling the route handler.

It receives the Request instance and any non-None return value is used for the response, bypassing the route handler.

cache_control: CacheControlHeader | None

A CacheControlHeader header to add to route handlers of this controller.

Can be overridden by route handlers.

dependencies: Dependencies | None

A string keyed dictionary of dependency Provider instances.

dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for (de)serializing and validation of request data.

etag: ETag | None

An etag header of type ETag to add to route handlers of this controller.

Can be overridden by route handlers.

exception_handlers: ExceptionHandlersMap | None

A map of handler functions to status codes and/or exception types.

guards: Sequence[Guard] | None

A sequence of Guard callables.

middleware: Sequence[Middleware] | None

A sequence of Middleware.

opt: Mapping[str, Any] | None

A string key mapping of arbitrary values that can be accessed in Guards or wherever you have access to Request or ASGI Scope.

owner: Router

The Router or Litestar app that owns the controller.

This value is set internally by Litestar and it should not be set when subclassing the controller.

parameters: ParametersMap | None

A mapping of Parameter definitions available to all application paths.

request_class: type[Request] | None

A custom subclass of Request to be used as the default request for all route handlers under the controller.

request_max_body_size: int | None | EmptyType

Maximum allowed size of the request body in bytes. If this size is exceeded, a ‘413 - Request Entity Too Large’ error response is returned.

response_class: type[Response] | None

A custom subclass of Response to be used as the default response for all route handlers under the controller.

response_cookies: ResponseCookies | None

A list of Cookie instances.

response_headers: ResponseHeaders | None

A string keyed dictionary mapping ResponseHeader instances.

return_dto: type[AbstractDTO] | None | EmptyType

AbstractDTO to use for serializing outbound response data.

security: Sequence[SecurityRequirement] | None

A sequence of dictionaries that to the schema of all route handlers under the controller.

signature_namespace: dict[str, Any]

A mapping of names to types for use in forward reference resolution during signature modelling.

signature_types: Sequence[Any]

A sequence of types for use in forward reference resolution during signature modelling.

These types will be added to the signature namespace using their __name__ attribute.

tags: Sequence[str] | None

A sequence of string tags that will be appended to the schema of all route handlers under the controller.

type_decoders: TypeDecodersSequence | None

A sequence of tuples, each composed of a predicate testing for type identity and a msgspec hook for deserialization.

type_encoders: TypeEncodersMap | None

A mapping of types to callables that transform them into types supported for serialization.

websocket_class: type[WebSocket] | None

A custom subclass of WebSocket to be used as the default websocket for all route handlers under the controller.

Dependencies

Success Stories domain dependency injection providers.

async provide_story_category_repository(db_session)[source]

Provide a StoryCategoryRepository instance.

Return type:

StoryCategoryRepository

async provide_story_category_service(db_session)[source]

Provide a StoryCategoryService instance.

Return type:

StoryCategoryService

async provide_story_repository(db_session)[source]

Provide a StoryRepository instance.

Return type:

StoryRepository

async provide_story_service(db_session)[source]

Provide a StoryService instance.

Return type:

StoryService

get_successstories_dependencies()[source]

Get all success stories domain dependency providers.

Return type:

dict