Metadata-Version: 2.5
Name: requests-wasi-http
Version: 0.1.0
Summary: WasiHttpAdapter: a requests transport adapter for wasi:http, targeting componentize-py guests
Requires-Python: >=3.11
Requires-Dist: requests>=2.32
Requires-Dist: typing-extensions>=4.4; python_version < '3.12'
Description-Content-Type: text/markdown

# requests-wasi-http

A [`requests`](https://requests.readthedocs.io/) transport adapter for
[WASI HTTP](https://github.com/WebAssembly/wasi-http) (`wasi:http@0.2`), so
`requests` works inside WebAssembly components built with
[componentize-py](https://github.com/bytecodealliance/componentize-py).

```python
import requests
import wit_world  # the componentize-py bindings for your WIT world
from wasi_http_adapter import WasiHttpAdapter

session = requests.Session()
adapter = WasiHttpAdapter(wit_world)  # or WasiHttpAdapter("wit_world")
session.mount("https://", adapter)
session.mount("http://", adapter)

response = session.get("https://postman-echo.com/get", timeout=5)
print(response.status_code, response.json())
```

Or use the convenience factory:
`session = wasi_http_adapter.wasi_session(wit_world)`.

The adapter never guesses where the bindings live: pass the componentize-py
bindings package for your WIT world (a world that imports
`wasi:http/outgoing-handler`) explicitly, either as the imported package
object or as its name.

Cookies, redirects, timeouts, and streaming downloads (`stream=True`) work
through a regular `Session`. TLS verification, client certificates, and
proxies are owned by the WASI host and therefore ignored; `Accept-Encoding`
is forced to `identity` since there is no transparent decompression.

## Development

```sh
uv run pytest          # tests
uv run ruff format .   # format
uv run ruff check .    # lint
uv run ty check        # types
```
