Add your description here
Project description
Overview
A client-side library that wraps server-side functions to enable RPC-style HTTP calls while allowing you to maintain control over HTTP requests.
Why?
Working across HTTP boundaries with a HTTP client and server introduces friction:
- Type information from the backend is lost — No type inference or validation for payloads and parameters sent in your HTTP requests
- Forced to rely on out-of-band documentation — All the information about the backend schema lives in OpenAPI/Swagger docs, where it's not visible in your editor.
How it works:
- Import server functions decorated with FastAPI/Flask on the client side
- Wrap them with
wrap_backend_call() - Call them as regular functions; the library translates calls into HTTP requests
- Handle the HTTP responses as per usual
A simple default HTTP implementation is included, but you can substitute your own with retry logic, caching, error handling, logging, etc.
Here is an example:
from server import get_item
from http_clientlib import set_default_configuration, wrap_backend_call
from http_clientlib.http import make_http_request
set_default_configuration(
base_url="http://production.backend.com", http_request_function=make_http_request
)
# Wrap the backend function and invoke it to make a HTTP request
get_item_http = wrap_backend_call(get_item)
response = get_item_http(item_id=42, page=2)
print(response) # HTTPResponse
An example with a POST endpoint and request body
# POST request with Pydantic model for the request body
create_item_http = wrap_backend_call(post_endpoint)
response = create_item_http(data=ItemData(id=1, name="A Box"))
# POST request using a dictionary directly
response = create_item_http(data={"id": 1, "name": "Sample Item"})
print(response)
@app.get("/items/{item_id}")
def get_item(item_id: int, page: int = 0) -> Annotated[dict, "GET /items/{item_id}"]:
"""A GET endpoint with both path and query parameters."""
return {"item_id": item_id}
class ItemData(BaseModel):
id: int
name: str
@app.post("/items")
def post_endpoint(data: ItemData) -> Annotated[dict, "POST /items"]:
"""A POST endpoint that accepts a Pydantic model as the request body."""
return {"message": f"Item {data} created"}
Benefits
- Type safety in the editor — Full type information available for IDE autocomplete and validation
- Endpoint schema visibility — Query params, path params, request body, headers, cookies are all immediately apparent in your code
- Docstring availability — Server function docstrings show up in the client IDE
- Code Generation not required — Additional tooling or auto-generated code Changes to server signatures are immediately caught on the client side.
Limitations
- Python-only — Works for a frontend/backend stack built in python
- Server code must be imported — Client needs access to server function definitions
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file http_clientlib-0.1.2.tar.gz.
File metadata
- Download URL: http_clientlib-0.1.2.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08367ebc37d7d561bffa3e9b7b3d13adf869f10d3f0b1f41de0fd78067123cb3
|
|
| MD5 |
4d64514704846a08f2d3daf50a2f7c52
|
|
| BLAKE2b-256 |
7d3ec74d64ba68ca43aeaa986f4e8b8877deaa50ebd961a419966b6fe4e17a95
|
File details
Details for the file http_clientlib-0.1.2-py3-none-any.whl.
File metadata
- Download URL: http_clientlib-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8ff3fb5db822b062d08000442227d91bf45c66f6dcf2e1a6f0c9b11b37990c8
|
|
| MD5 |
f1a10d8439fd239d1ff8c26e5c8283d8
|
|
| BLAKE2b-256 |
e04237aed69687bca807652382d13646f3a5616a71def4e37635b38b81e059a8
|