Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .skills/python-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ EggfetchError
└── HTTPStatusError
```

## HTTPX Compatibility Layer

The `eggfetch.compat.httpx` module provides an HTTPX 0.28.1 drop-in facade over the eggfetch Rust engine. Import path:

```python
from eggfetch.compat.httpx import Client, AsyncClient, Request, Response
```

**Phase 2 implements:**
- Value objects: `URL`, `QueryParams`, `Headers`, `Cookies`, `Timeout`, `Limits`, `Proxy`
- Status code helpers (`codes`)
- Request and Response objects with full HTTPX-compatible metadata
- `Client` and `AsyncClient` with constructor signatures, merge semantics, `build_request()`, `send()`
- Top-level helpers: `get`, `post`, `put`, `patch`, `delete`, `head`, `options`, `request`, `stream`
- Complete exception hierarchy matching HTTPX MRO
- Stubs for auth flows, transports, and stream classes (Phase 3+)

**Testing the compat layer:**

```sh
cd crates/eggfetch-python && maturin develop
EGGFETCH_COMPAT_REQUIRED=1 pytest crates/eggfetch-python/tests/compat/ -v --strict-markers
```

Validate profiles and manifests:

```sh
python scripts/validate_httpx_compat_profile.py compat/httpx/0.28.1
python scripts/generate_httpx_api_manifest.py --package httpx --output /tmp/httpx.json
python scripts/generate_httpx_api_manifest.py --package eggfetch --output /tmp/eggfetch.json
python scripts/compare_httpx_api_manifest.py \
--reference /tmp/httpx.json \
--candidate /tmp/eggfetch.json \
--allowed compat/httpx/0.28.1/allowed-differences.toml
```

## Architecture Reference

- Python bindings: `docs/architecture/python-bindings.md`
Expand Down
17 changes: 17 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ Key flags: `http2`, `http3`, `json`, `compression-{gzip,brotli,zstd,deflate}`, `

The CLI enables: cookies, multipart, proxy. The Python binding enables all features including http3. `test-util` enables `tokio/test-util` for deterministic time testing.

## HTTPX Compatibility Layer

The `eggfetch.compat.httpx` module provides an HTTPX 0.28.1 drop-in facade. Import it as:

```python
from eggfetch.compat.httpx import Client, AsyncClient, Request, Response, URL, Headers, Cookies
```

Phase 2 is complete — value objects, request/response, exception hierarchy, client constructors, and merge semantics are implemented. See `plans/httpx-drop-in-phase-2-status.md` for status.

Run compat tests:

```sh
cd crates/eggfetch-python && maturin develop
EGGFETCH_COMPAT_REQUIRED=1 pytest crates/eggfetch-python/tests/compat/ -v --strict-markers
```

## Tests

Colocated `#[cfg(test)] mod tests` blocks. ~750+ Rust, ~463+ Python, ~40+ FFI tests.
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ Phase 1 (production semantics) closes these gaps:

See [`compat/httpx/0.28.1/`](compat/httpx/0.28.1/) for the full profile and [`docs/reference/compatibility.md`](docs/reference/compatibility.md) for the feature matrix.

## HTTPX Drop-In Compatibility

eggfetch provides a drop-in HTTPX 0.28.1 compatibility facade:

```python
from eggfetch.compat.httpx import Client, AsyncClient, Request, Response, URL, Headers

# Drop-in replacement for httpx
client = Client()
response = client.get("https://example.com")
```

Phase 2 (object model and core API parity) is complete. See [`plans/httpx-drop-in-phase-2-status.md`](plans/httpx-drop-in-phase-2-status.md) for details, [`compat/httpx/0.28.1/`](compat/httpx/0.28.1/) for the pinned profile, and [`docs/reference/compatibility.md`](docs/reference/compatibility.md) for the feature matrix.

## Target API Shapes

The Python API targets familiar requests/httpx patterns:
Expand Down
Empty file.
293 changes: 293 additions & 0 deletions crates/eggfetch-python/python/eggfetch/compat/httpx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
"""HTTPX 0.28.1-compatible facade for eggfetch.

This package provides a drop-in compatibility layer so that existing
HTTPX code can run against the eggfetch Rust engine with minimal changes.
"""

from __future__ import annotations

__description__ = "A HTTPX-compatible facade for eggfetch."
__title__ = "eggfetch[httpx-compat]"
__version__ = "0.28.1"

# ── Phase 2: pure-Python value objects ──────────────────────────────────
from eggfetch.compat.httpx._urls import URL, QueryParams
from eggfetch.compat.httpx._headers import Headers
from eggfetch.compat.httpx._cookies import Cookies
from eggfetch.compat.httpx._timeout import Timeout
from eggfetch.compat.httpx._limits import Limits
from eggfetch.compat.httpx._proxy import Proxy
from eggfetch.compat.httpx._status_codes import codes
from eggfetch.compat.httpx._exceptions import (
CloseError,
ConnectError,
ConnectTimeout,
CookieConflict,
DecodingError,
HTTPError,
HTTPStatusError,
InvalidURL,
LocalProtocolError,
NetworkError,
PoolTimeout,
ProtocolError,
ProxyError,
ReadError,
ReadTimeout,
RemoteProtocolError,
RequestError,
RequestNotRead,
ResponseNotRead,
StreamClosed,
StreamConsumed,
StreamError,
TimeoutException,
TooManyRedirects,
TransportError,
UnsupportedProtocol,
WriteError,
WriteTimeout,
)

# ── Phase 3+ / 4+: stubs for transports, auth, streams, client ────────
# These exist so the import line ``from eggfetch.compat.httpx import …``
# works. Real implementations arrive in later phases.

_USE_CLIENT_DEFAULT = object()


def _stub_factory(name: str, msg: str | None = None):
"""Return a class that raises NotImplementedError on instantiation."""
_msg = msg or f"eggfetch does not support {name}"

class _Stub:
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)

def __init__(self, *args, **kwargs):
raise NotImplementedError(_msg)

_Stub.__name__ = name
_Stub.__qualname__ = name
return _Stub


# Auth base class (Phase 3+)
class Auth:
"""Base class for authentication."""

def auth_flow(self, request):
raise NotImplementedError("eggfetch auth flows not yet implemented")


class _NetRCAuth(Auth):
"""Stub for NetRCAuth."""

def __init__(self, *args, **kwargs):
raise NotImplementedError("eggfetch does not support NetRCAuth")


NetRCAuth = _NetRCAuth


class _BasicAuth(Auth):
"""HTTPX-compatible BasicAuth (Phase 2 stub)."""

def __init__(self, username: str = "", password: str = "", *, encoding="latin-1"):
self._username = username
self._password = password
self._encoding = encoding

def auth_flow(self, request):
raise NotImplementedError("eggfetch BasicAuth flow not yet implemented")

def __repr__(self):
return f"BasicAuth(username={self._username!r})"


BasicAuth = _BasicAuth


class _DigestAuth(Auth):
"""HTTPX-compatible DigestAuth (Phase 2 stub)."""

def __init__(self, username: str, password: str):
self._username = username
self._password = password

def auth_flow(self, request):
raise NotImplementedError("eggfetch DigestAuth flow not yet implemented")

def __repr__(self):
return f"DigestAuth(username={self._username!r})"


DigestAuth = _DigestAuth

# Transport stubs (Phase 4+)
class _BaseTransport:
def handle_request(self, request):
raise NotImplementedError("eggfetch does not support custom transports")

def close(self):
pass


class _AsyncBaseTransport:
async def handle_async_request(self, request):
raise NotImplementedError("eggfetch does not support custom transports")

async def aclose(self):
pass


BaseTransport = _BaseTransport
AsyncBaseTransport = _AsyncBaseTransport

HTTPTransport = _stub_factory("HTTPTransport")
AsyncHTTPTransport = _stub_factory("AsyncHTTPTransport")
MockTransport = _stub_factory("MockTransport")
ASGITransport = _stub_factory("ASGITransport")
WSGITransport = _stub_factory("WSGITransport")

# Stream stubs
class ByteStream:
def __init__(self, *args, **kwargs):
raise NotImplementedError("eggfetch does not support custom byte streams")


class SyncByteStream(ByteStream):
pass


class AsyncByteStream:
def __init__(self, *args, **kwargs):
raise NotImplementedError("eggfetch does not support custom byte streams")


# Phase 2: Request / Response
from eggfetch.compat.httpx._request import Request
from eggfetch.compat.httpx._response import Response

# Client / AsyncClient
from eggfetch.compat.httpx._client import Client, AsyncClient


# Top-level convenience functions
def request(*args, **kwargs):
with Client() as client:
return client.request(*args, **kwargs)


def get(*args, **kwargs):
with Client() as client:
return client.get(*args, **kwargs)


def post(*args, **kwargs):
with Client() as client:
return client.post(*args, **kwargs)


def put(*args, **kwargs):
with Client() as client:
return client.put(*args, **kwargs)


def patch(*args, **kwargs):
with Client() as client:
return client.patch(*args, **kwargs)


def delete(*args, **kwargs):
with Client() as client:
return client.delete(*args, **kwargs)


def head(*args, **kwargs):
with Client() as client:
return client.head(*args, **kwargs)


def options(*args, **kwargs):
with Client() as client:
return client.options(*args, **kwargs)


def stream(*args, **kwargs):
with Client() as client:
with client.stream(*args, **kwargs) as response:
return response


USE_CLIENT_DEFAULT = _USE_CLIENT_DEFAULT

__all__ = [
"__description__",
"__title__",
"__version__",
"ASGITransport",
"AsyncBaseTransport",
"AsyncByteStream",
"AsyncClient",
"AsyncHTTPTransport",
"Auth",
"BaseTransport",
"BasicAuth",
"ByteStream",
"Client",
"CloseError",
"codes",
"ConnectError",
"ConnectTimeout",
"CookieConflict",
"Cookies",
"DecodingError",
"delete",
"DigestAuth",
"get",
"head",
"Headers",
"HTTPError",
"HTTPStatusError",
"HTTPTransport",
"InvalidURL",
"Limits",
"LocalProtocolError",
"MockTransport",
"NetRCAuth",
"NetworkError",
"options",
"patch",
"PoolTimeout",
"post",
"ProtocolError",
"Proxy",
"ProxyError",
"put",
"QueryParams",
"ReadError",
"ReadTimeout",
"RemoteProtocolError",
"request",
"Request",
"RequestError",
"RequestNotRead",
"Response",
"ResponseNotRead",
"stream",
"StreamClosed",
"StreamConsumed",
"StreamError",
"SyncByteStream",
"Timeout",
"TimeoutException",
"TooManyRedirects",
"TransportError",
"UnsupportedProtocol",
"URL",
"USE_CLIENT_DEFAULT",
"WriteError",
"WriteTimeout",
"WSGITransport",
]
Loading
Loading