Skip to content

CmfClient

cl_forge.cmf.CmfClient

CmfClient(api_key: str)

Base client for interacting with the CMF API.

Notes

The API is free to use, but has a limit of 10.000 monthly requests per user and requires an API key for authentication, which can be requested in Contact and is usually sent to the given email during the day.

Attributes:

Name Type Description
api_key str

The API ticket used for authenticating requests to the CMF API.

base_url str

The base URL of the CMF API.

Raises:

Type Description
EmptyApiKey

If no API key is provided or it's empty.

Parameters:

Name Type Description Default
api_key str

The API key for authenticating with the CMF API.

required
Source code in src/cl_forge/core/impl/rs_cl_forge/rs_cmf.pyi
def __init__(self, api_key: str) -> None:
    """
    Initializes the CMF client with the provided API key.

    Parameters
    ----------
    api_key: str
        The API key for authenticating with the CMF API.
    """

api_key property

api_key: str

Gets the API Key used for authenticating requests.

Returns:

Type Description
str

The API Key.

base_url property

base_url: str

Gets the base URL of the CMF API.

Returns:

Type Description
str

The base URL of the CMF API.

get

get(
    path: str, fmt: Literal["json", "xml"] = "json"
) -> dict[str, list[dict[str, str]]] | str

Sends a GET request to the specified CMF API endpoint.

Notes

See the API Docs for all the available endpoints.

Parameters:

Name Type Description Default
path str

The API endpoint path. Must start with '/'.

required
fmt Literal['json', 'xml']

The format of the response. Can be 'json', 'xml'.

'json'

Returns:

Type Description
dict[str, list[dict[str, str]]] | str

The response from the CMF API. Returns a dict if format is 'json' and a str if format is 'xml'.

Source code in src/cl_forge/core/impl/rs_cl_forge/rs_cmf.pyi
def get(
        self,
        path: str,
        fmt: Literal["json", "xml"] = "json"
) -> dict[str, list[dict[str, str]]] | str:
    """
    Sends a GET request to the specified CMF API endpoint.

    Notes
    -----
    See the [API Docs](https://api.cmfchile.cl/documentacion/index.html)
    for all the available endpoints.

    Parameters
    ----------
    path : str
        The API endpoint path. Must start with ``'/'``.
    fmt : Literal["json", "xml"]
        The format of the response. Can be ``'json'``, ``'xml'``.

    Returns
    -------
    dict[str, list[dict[str, str]]] | str
        The response from the CMF API. Returns a ``dict`` if format is
        ``'json'`` and a ``str`` if format is ``'xml'``.
    """