Skip to main content

Declarative HTTP clients for the Pico ecosystem: @http_client classes with @get/@post stubs over httpx.

Project description

pico-httpx

PyPI version License: MIT CI codecov Docs

Declarative HTTP clients for the pico ecosystem: write the interface, get the implementation. Powered by httpx.

Installation

pip install pico-httpx

Quick start

import httpx
from pico_httpx import http_client, get, post

@http_client(base_url="https://api.example.com")   # or resolve from config, see below
class UsersApi:
    @get("/users/{user_id}")
    def get_user(self, user_id: int, verbose: bool | None = None) -> dict: ...

    @post("/users")
    async def create_user(self, json: dict) -> dict: ...

    @get("/users/{user_id}/avatar")
    def avatar(self, user_id: int) -> httpx.Response: ...

The class is a regular @component — inject it anywhere. Rules:

  • {placeholders} in the path bind to method parameters.
  • A parameter named json is the request body.
  • Every other parameter becomes a query param (None values are dropped).
  • Return annotation httpx.Response gets the raw response; anything else gets response.json() (or None on an empty body). Non-2xx raises httpx.HTTPStatusError.
  • Sync stubs share an httpx.Client, async stubs an httpx.AsyncClient; both close on container shutdown.

Base URL from config instead of code:

http:
  timeout_seconds: 10
  clients:
    users:
      base_url: https://users.internal
@http_client(name="users")
class UsersApi: ...

Compose with the rest of the ecosystem: stack @retryable / @circuit_breaker (pico-resilience) on the same methods, and pico-otel traces the underlying httpx calls.

Documentation

Full documentation: https://dperezcabrera.github.io/pico-httpx/

License

MIT

Project details


Download files

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

Source Distribution

pico_httpx-0.1.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

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

pico_httpx-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file pico_httpx-0.1.0.tar.gz.

File metadata

  • Download URL: pico_httpx-0.1.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pico_httpx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd1aa42b784422307e0d18728b16e40bf7e27d6e9799a918ecd6a01c6f850675
MD5 0900a8d0e4f902b1609108f3d202bd2d
BLAKE2b-256 74dfe98f4c8c4c25284cc151bfdf57c6fb468ab3457af4de39af8777f37abb22

See more details on using hashes here.

Provenance

The following attestation bundles were made for pico_httpx-0.1.0.tar.gz:

Publisher: publish-to-pypi.yml on dperezcabrera/pico-httpx

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

File details

Details for the file pico_httpx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pico_httpx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pico_httpx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21d35455413b02be436e6edcb7bc386fa76350c51e33b57a4b02407a4b0665f3
MD5 62c01f4250ff4076b0a5008adb7b4fa0
BLAKE2b-256 2eb95205dc6c17b6076576047203a061ff03b7b0a431fc7f17809bda5cbcfbce

See more details on using hashes here.

Provenance

The following attestation bundles were made for pico_httpx-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on dperezcabrera/pico-httpx

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page