Skip to content

CmfEndpoint

cl_forge.core.endpoints.CmfEndpoint

CmfEndpoint(
    api_key: str,
    path: str,
    record_class: type[T],
    root_key: str,
)

Base class for CMF API endpoints.

Parameters:

Name Type Description Default
api_key str

CMF API key.

required
path str

Path to the endpoint.

required
record_class type[T]

Record class for the endpoint.

required
root_key str

Root key in the API response containing the data.

required
Source code in src/cl_forge/core/endpoints.py
def __init__(
    self,
    api_key: str,
    path: str,
    record_class: type[T],
    root_key: str
) -> None:
    """
    Initialize the endpoint client.

    Parameters
    ----------
    api_key : str
        CMF API key.
    path : str
        Path to the endpoint.
    record_class : type[T]
        Record class for the endpoint.
    root_key : str
        Root key in the API response containing the data.
    """
    client = CmfClient(api_key=api_key)
    object.__setattr__(self, "_client", client)
    object.__setattr__(self, "_path", path)
    object.__setattr__(self, "_record_class", record_class)
    object.__setattr__(self, "_root_key", root_key)

current

current() -> T

Get the latest available record.

Source code in src/cl_forge/core/endpoints.py
def current(self) -> T:
    """
    Get the latest available record.
    """
    return self._fetch_current(
        self._client,
        self._path,
        self._record_class,
        self._root_key
    )

year

year(year: int | None = None) -> list[T]

Get the records for a given year.

Parameters:

Name Type Description Default
year int | None
None
Source code in src/cl_forge/core/endpoints.py
def year(self, year: int | None = None) -> list[T]:
    """
    Get the records for a given year.

    Parameters
    ----------
    year : int | None
    """
    return self._fetch_year(
        self._client,
        self._path,
        self._record_class,
        self._root_key,
        year
    )