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.

Your client side code can now have descriptive type information and docstrings right in the editor!

Screenshot of editor with type information for a backend function

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.3.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.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file http_clientlib-0.1.3.tar.gz.

File metadata

  • Download URL: http_clientlib-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 cdb255d49322e6d9060f22543659a13b281c1e10d28a84092437b9201854de23
MD5 552b3bb9de54958cb9f9044d6b5097f4
BLAKE2b-256 97d404b53457a80ad00a58ab5a620eaaf77d8de4e3d6c4f81d23062c1242eb4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for http_clientlib-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d92010d30948a8eab36cc1d13d38420f5c379f50ba698641bc1767437068a72a
MD5 9fc3a9b20f9c3c066fca4304c78461f6
BLAKE2b-256 94c4cfec11014ec3f1d76a6b8c1607175bc7f4675ed0db7ba9ee45184f14efb2

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