Skip to main content

Chile Public Market SDK

Unofficial, typed, synchronous and asynchronous Python SDK for Chile's Mercado Público APIs.

Status: alpha (0.4.0). The upstream services include legacy contracts and may add fields. Models validate known fields while preserving new ones.

Requirements

  • Python 3.12 or newer.
  • An access ticket requested through ChileCompra.

Installation

pip install chile-public-market-sdk

Secure configuration

The SDK never includes or manages tickets. Pass one explicitly:

from chile_public_market_sdk import SyncChilePublicMarketSDK

sdk = SyncChilePublicMarketSDK(ticket="YOUR_TICKET")

Or define CHILE_PUBLIC_MARKET_TICKET:

export CHILE_PUBLIC_MARKET_TICKET="YOUR_TICKET"

Git ignores .env and env.yaml. Loading them through Docker Compose, Kubernetes, envyaml, python-dotenv, or another secret-management mechanism is the consumer application's responsibility. The SDK itself does not read configuration files.

Synchronous usage

from datetime import date

from chile_public_market_sdk import SyncChilePublicMarketSDK
from chile_public_market_sdk.enums import TenderStatus

with SyncChilePublicMarketSDK() as sdk:
    response = sdk.get_tenders(
        date=date(2026, 6, 12),
        status=TenderStatus.PUBLISHED,
    )
    for tender in response.items:
        print(tender.external_code, tender.name)

    order = sdk.get_purchase_orders(code="2097-241-SE14")
    supplier = sdk.find_supplier("70.017.820-k")
    buyers = sdk.get_buyers()

Asynchronous usage

import asyncio

from chile_public_market_sdk import AsyncChilePublicMarketSDK
from chile_public_market_sdk.enums import AgilePurchaseStatus


async def main() -> None:
    async with AsyncChilePublicMarketSDK() as sdk:
        page = await sdk.get_agile_purchases(
            last_change_ttl_ms=300_000,
            statuses=[AgilePurchaseStatus.PUBLISHED],
            page_size=50,
        )
        detail = await sdk.get_agile_purchase(page.items[0].code)
        print(detail.name)


asyncio.run(main())

Endpoint coverage

Resource SDK method API
Tenders get_tenders v1
Purchase orders get_purchase_orders v1
Suppliers find_supplier v1
Buyer organizations get_buyers v1
Agile Purchase listing and filters get_agile_purchases v2
Agile Purchase details get_agile_purchase v2

V1 date filters accept a date or the original ddmmyyyy format. Agile Purchase accepts ISO-8601 dates, multiple statuses and regions, pagination, and sorting.

Client classes and API versions

The SDK exposes separate synchronous and asynchronous classes:

  • SyncChilePublicMarketClient / SyncChilePublicMarketSDK
  • AsyncChilePublicMarketClient / AsyncChilePublicMarketSDK

ChileCompra endpoint contracts are versioned independently under chile_public_market_sdk.api.v1 and chile_public_market_sdk.api.v2. Future upstream contracts will follow api.v{version}. SDK releases remain 0.x until the public Python API is stable enough for 1.0.0.

Errors

Every public exception inherits from ChilePublicMarketError:

  • ConfigurationError: no ticket was supplied.
  • RequestValidationError: incompatible or invalid filters.
  • AuthenticationError: HTTP 401 or 403.
  • NotFoundError: HTTP 404.
  • RateLimitError: HTTP 429; exposes retry_after.
  • APIError: any other API error.
  • RequestTimeoutError: a configured timeout was exceeded.
  • NetworkError: a connection or network protocol failed.
  • TransportError: another HTTP transport failure.
  • ResponseValidationError: invalid JSON or an unexpected contract.

Reliability

Retries are opt-in. They cover connection failures and HTTP 429, 500, 502, 503, and 504 responses. A 429 response is retried only when the server provides a valid Retry-After value, which avoids repeatedly consuming a daily quota.

from chile_public_market_sdk import (
    ClientConfig,
    RetryConfig,
    SyncChilePublicMarketSDK,
    TimeoutConfig,
)

config = ClientConfig(
    ticket="YOUR_TICKET",
    timeout=TimeoutConfig(connect=5, read=30, write=10, pool=5),
    retry=RetryConfig(max_attempts=3),
)

with SyncChilePublicMarketSDK(config=config) as sdk:
    tenders = sdk.get_tenders()

Development

poetry install --extras "dev docs"
poetry run pytest
poetry run ruff check .
poetry run mypy
poetry build

Read CONTRIBUTING.md and SECURITY.md before submitting changes or reporting vulnerabilities.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chile_public_market_sdk-0.4.2.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chile_public_market_sdk-0.4.2-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file chile_public_market_sdk-0.4.2.tar.gz.

File metadata

  • Download URL: chile_public_market_sdk-0.4.2.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for chile_public_market_sdk-0.4.2.tar.gz
Algorithm Hash digest
SHA256 9d734ffab683fc76cb728318047b3a1e582b09819f8b3f54bf881e875e18093f
MD5 f1a7c4f24c18a85a25412b219aa3c520
BLAKE2b-256 ff31a29939e72a9d22a20d935a0a0b039d978d7573b7143e20e12c9a7da4acd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for chile_public_market_sdk-0.4.2.tar.gz:

Publisher: publish.yml on ezer-mackenzie/chile-public-market-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chile_public_market_sdk-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for chile_public_market_sdk-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d1446d841838e95d6edfba4ac2a1a885af33f5223ab4c2d9d7ef0c23236e02e2
MD5 ce65f1995fb890a94aadb84134f20cd5
BLAKE2b-256 3c95011e84963f259632491dd362ceebf7930ce953fcf8c32d205fa36e920053

See more details on using hashes here.

Provenance

The following attestation bundles were made for chile_public_market_sdk-0.4.2-py3-none-any.whl:

Publisher: publish.yml on ezer-mackenzie/chile-public-market-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.0.1

2 files

1.0.0

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

2 files

This release

0.4.2 This release

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page