Skip to main content

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:

  1. Type information from the backend is lost — No type inference or validation for payloads and parameters sent in your HTTP requests
  2. 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

  1. Type safety in the editor — Full type information available for IDE autocomplete and validation
  2. Endpoint schema visibility — Query params, path params, request body, headers, cookies are all immediately apparent in your code
  3. Docstring availability — Server function docstrings show up in the client IDE
  4. Code Generation not required — Additional tooling or auto-generated code Changes to server signatures are immediately caught on the client side.

Limitations

  1. Python-only — Works for a frontend/backend stack built in python
  2. 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

http_clientlib-0.1.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

http_clientlib-0.1.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

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

Hashes for http_clientlib-0.1.2.tar.gz
Algorithm Hash digest
SHA256 08367ebc37d7d561bffa3e9b7b3d13adf869f10d3f0b1f41de0fd78067123cb3
MD5 4d64514704846a08f2d3daf50a2f7c52
BLAKE2b-256 7d3ec74d64ba68ca43aeaa986f4e8b8877deaa50ebd961a419966b6fe4e17a95

See more details on using hashes here.

File details

Details for the file http_clientlib-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for http_clientlib-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b8ff3fb5db822b062d08000442227d91bf45c66f6dcf2e1a6f0c9b11b37990c8
MD5 f1a10d8439fd239d1ff8c26e5c8283d8
BLAKE2b-256 e04237aed69687bca807652382d13646f3a5616a71def4e37635b38b81e059a8

See more details on using hashes here.

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