Skip to main content

Declarative HTTP client SDK for Python microservices

Project description

unitpulse-feign

Declarative HTTP client for Python microservices, inspired by Spring Cloud OpenFeign. Integrates with unitpulse-discovery to call services by name with automatic load balancing.

Installation

pip install "./unitpulse-feign"

Usage

from unitpulse_feign import setup_feign, get, post, put, delete, patch

# Must be called after setup_discovery
setup_feign(app)

@app.feign.client("target-service", lb_strategy="round_robin")
class TargetClient:
    @get("/api/users/{user_id}")
    def get_user(self, user_id: int) -> dict: pass

    @post("/api/users")
    def create_user(self, body: dict) -> dict: pass

# Create singleton and reuse — do NOT instantiate per request
client = TargetClient()
response = client.get_user(user_id=123)
response = client.create_user(body={"name": "Alice"})

Parameters

setup_feign(app)

Attaches app.feign to the app. Must be called after setup_discovery.

@app.feign.client(...)

Parameter Type Default Description
service_name str Target service name (discovery mode)
host str Direct host (direct mode, no discovery)
port int Direct port (direct mode)
scheme str "http" "http" or "https"
timeout int 5 Request timeout (seconds)
lb_strategy str "round_robin" Load balancing strategy

Modes:

  • Discovery mode: provide service_name — instances resolved via app.discovery
  • Direct mode: provide host + port — bypasses discovery

HTTP Method Decorators

Decorator Method
@get(path) GET
@post(path) POST
@put(path) PUT
@delete(path) DELETE
@patch(path) PATCH

Path supports {variable} placeholders matched to keyword arguments:

@get("/api/users/{user_id}/orders/{order_id}")
def get_order(self, user_id: int, order_id: int) -> dict: pass

client.get_order(user_id=1, order_id=42)

Load Balancing Strategies

Strategy Description
round_robin Cycles through instances in order
random Randomly selects an instance
weighted Weighted random based on weight in instance metadata
least_conn Selects instance with fewest active connections

Async Support

Each method exposes .async_call for use in async contexts:

result = await client.get_user.async_call(user_id=123)

License

MIT

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

unitpulse_feign-0.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

unitpulse_feign-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file unitpulse_feign-0.1.0.tar.gz.

File metadata

  • Download URL: unitpulse_feign-0.1.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for unitpulse_feign-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9735955009ffa4cc64126ecd8a1b48de55c518dc70da1af6c704215e615b5263
MD5 191f28374b371cc17738513d141f8c8b
BLAKE2b-256 b5f6499f9c125f75052c1ba911516e9d3a467463875c613e389986e4525ccdce

See more details on using hashes here.

File details

Details for the file unitpulse_feign-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for unitpulse_feign-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84cc9b4073db8a8f071171a0bf9d2c569fa908fd0bb19e004d5153dce8b656cc
MD5 94c4170a548ce12abc7ee1d4bac0cf2b
BLAKE2b-256 af89256b44ffa6d141d80048e0d257acca105961fd9f8e9471eaeabeab30a007

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