Skip to content

dependencies

FastAPI dependencies provided to endpoint functions.

This module defines various dependencies that can be used in FastAPI route functions. These dependencies include retrieving the job pool, creating database sessions, and validating the content type.

Functions

db_session_dependency

db_session_dependency() -> Generator[SASession, None, None]

A generator function that yields a SQLAlchemy session.

Intended use case is to be used as a dependency in FastAPI route functions.

Yields:

  • SASession ( SASession ) –

    A SQLAlchemy session object.

job_pool_dependency

job_pool_dependency(request: Request) -> ThreadPoolExecutor

Retrieve the job pool from the application state.

Parameters:

  • request (Request) –

    The incoming request.

Returns:

  • ThreadPoolExecutor ( ThreadPoolExecutor ) –

    job pool instance

neo4j_session_dependency

neo4j_session_dependency() -> (
    Generator[NJSession, None, None]
)

require_content_type_text_plain

require_content_type_text_plain(
    content_type: str = Header(...),
)

Validates the HTTP content type and raises an exception if it is not ‘text/plain’.

The intended use case applies to settings where most other API endpoints require clients to sent JSON content. Moreover there isn’t an easy way to indicate content type in the openapi documentation. Therefore this dependency will hopefully save users some time by telling them exactly what the problem is.

Parameters:

  • content_type (str, default: Header(...) ) –

    The content type to validate.

Raises:

  • HTTPException

    If the content type is not ‘text/plain’.

Returns:

  • None