Skip to content

MarketClient

cl_forge.market.MarketClient

MarketClient(ticket: str)

Represents a client for interacting with the Chilean Public Market API.

Notes

The API is free to use, but requires an API ticket for authentication which can be requested in Contact and is usually sent to the given email during the day.

Attributes:

Name Type Description
ticket str

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

base_url str

The base URL of the market API endpoint.

Parameters:

Name Type Description Default
ticket str

The API ticket for authenticating requests.

required
Source code in src/cl_forge/core/impl/rs_cl_forge/rs_market.pyi
def __init__(self, ticket: str) -> None:
    """
    Initializes the MarketClient with the provided API ticket.

    Parameters
    ----------
    ticket : str
        The API ticket for authenticating requests.
    """

ticket property

ticket: str

Gets the API ticket used for authenticating requests.

Returns:

Type Description
str

The API ticket.

base_url property

base_url: str

Gets the base URL of the market API endpoint.

Returns:

Type Description
str

The base URL of the market API.

get

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

Sends a GET request to the specified path of the market API.

Notes

See the API Docs for all the available endpoints.

Parameters:

Name Type Description Default
path str

The API path to send the GET request to.

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

The format of the response. Defaults to "json". When set to "xml", the response will be returned as a string, otherwise it will be parsed as a dictionary.

'json'
params dict[str, Any] | None

Optional query parameters to include in the request.

None

Returns:

Type Description
dict[str, Any] | str

The JSON response from the API as a dictionary or the XML response as a string.

Raises:

Type Description
ValueError

If the ticket (API key) is included in params.

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

    Notes
    -----
    See the [API Docs](https://api.mercadopublico.cl/modules/api.aspx)
    for all the available endpoints.

    Parameters
    ----------
    path : str
        The API path to send the GET request to.
    fmt : Literal["json", "xml"]
        The format of the response. Defaults to "json".
        When set to "xml", the response will be returned as
        a string, otherwise it will be parsed as a dictionary.
    params : dict[str, Any] | None
        Optional query parameters to include in the request.

    Returns
    -------
    dict[str, Any] | str
        The JSON response from the API as a dictionary or the XML response
        as a string.

    Raises
    ------
    ValueError
        If the ticket (API key) is included in `params`.
    """