Skip to content

Reference: dependency

Everything used to mark an endpoint as versioned. Imported from the package root:

from fastapi_easy_versioning import VersionInfo, VersioningSupport, versioning

versioning

fastapi_easy_versioning.versioning

versioning(
    *, until: int | None = None
) -> VersioningSupport

Dependency factory to mark endpoints as versioned.

Marking is opt-in: an endpoint without this dependency is invisible to versioning and stays only in the version that declares it. Inheritance itself is performed by VersioningMiddleware.

Usage
@router.get("/path", dependencies=[Depends(versioning(until=...))])
def endpoint():
    ...

# Apply versioning to all endpoints in the router
router = APIRouter(dependencies=[Depends(versioning(until=...))])
router.add_api_route("/path", endpoint)

# Or inject versioning metadata into the endpoint
@router.get("/path")
def endpoint(data: Annotated[VersionInfo, Depends(versioning())]):
    from_version = data.origin
    end_supported_version = data.until

Parameters:

Name Type Description Default
until int | None

The last version the endpoint is available in, inclusive. If None, the endpoint remains available through the latest version — including versions mounted later. When a route carries several versioning dependencies (say one on the router and one on the endpoint), the smallest declared until wins. An until below the declaring version emits a UserWarning: the endpoint is then inherited nowhere. Defaults to None.

None

Returns:

Name Type Description
VersioningSupport VersioningSupport

A dependency callable compatible with FastAPI's Depends(). Injected into an endpoint signature, it yields a VersionInfo.

VersioningSupport

fastapi_easy_versioning.VersioningSupport

VersioningSupport(*, until: int | None = None)

Callable dependency marking an endpoint as versioned.

Instances are produced by versioning and are meant to be passed to Depends(); construct them through that factory rather than directly. An instance only carries the declared until and is never mutated — the resolved per-route metadata lives in a registry on the version sub-app, so the same instance can safely be shared by a router included into several versions.

Parameters:

Name Type Description Default
until int | None

The last supported version, as declared at the call site. Defaults to None.

None

VersionInfo

fastapi_easy_versioning.VersionInfo

Bases: NamedTuple

Resolved versioning metadata of an endpoint.

Yielded by the versioning dependency when it is injected into an endpoint signature. Both fields are resolved by the middleware against the actually mounted versions, so until is a concrete version number even when the endpoint declared none.

Usage
@app_v1.get("/endpoint")
def endpoint(version: Annotated[VersionInfo, Depends(versioning())]) -> str:
    return f"available from v{version.origin} through v{version.until}"

origin instance-attribute

origin: int

The version that declared the endpoint.

until instance-attribute

until: int

The last version the endpoint is available in.

When no until was declared, this is the latest mounted version at the time versioning was built.