Metadata-Version: 2.4
Name: pico-httpx
Version: 0.1.0
Summary: Declarative HTTP clients for the Pico ecosystem: @http_client classes with @get/@post stubs over httpx.
Author-email: David Perez Cabrera <dperezcabrera@gmail.com>
License: MIT License
        
        Copyright (c) 2025 David Pérez Cabrera
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/dperezcabrera/pico-httpx
Project-URL: Documentation, https://dperezcabrera.github.io/pico-httpx/
Project-URL: Repository, https://github.com/dperezcabrera/pico-httpx
Project-URL: Changelog, https://github.com/dperezcabrera/pico-httpx/blob/main/CHANGELOG.md
Project-URL: Issue Tracker, https://github.com/dperezcabrera/pico-httpx/issues
Keywords: http,client,httpx,declarative,rest,ioc,spring boot
Classifier: Development Status :: 4 - Beta
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pico-ioc>=2.2.0
Requires-Dist: httpx>=0.28
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: pytest-asyncio; extra == "dev"
Requires-Dist: pytest-cov>=5; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Dynamic: license-file

# pico-httpx

[![PyPI version](https://img.shields.io/pypi/v/pico-httpx.svg)](https://pypi.org/project/pico-httpx/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![CI](https://github.com/dperezcabrera/pico-httpx/actions/workflows/ci.yml/badge.svg)](https://github.com/dperezcabrera/pico-httpx/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/dperezcabrera/pico-httpx/branch/main/graph/badge.svg)](https://codecov.io/gh/dperezcabrera/pico-httpx)
[![Docs](https://img.shields.io/badge/docs-mkdocs-blue)](https://dperezcabrera.github.io/pico-httpx/)

Declarative HTTP clients for the [pico ecosystem](https://github.com/dperezcabrera/pico-ioc): write the interface, get the implementation. Powered by httpx.

## Installation

```bash
pip install pico-httpx
```

## Quick start

```python
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:

```yaml
http:
  timeout_seconds: 10
  clients:
    users:
      base_url: https://users.internal
```

```python
@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
