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.2.1.tar.gz (9.4 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.2.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for unitpulse_feign-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3a282f8a51942b5d5b19072e1967d27e86d9f52f0edf8f5f42a8bcb0f2c3fce0
MD5 318c8380ca6097919e4518514bf5ff35
BLAKE2b-256 c7a8587988f968f018201e1b8cf70a40b07000c50f28afd42eadca99e9a94397

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for unitpulse_feign-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b26bd96ded4cf407584a39f93926c40422a26f5013dd50abd5318c20e20df45
MD5 96a51c37d331dc206f5b61ad2f5ef129
BLAKE2b-256 02bff1344988fb47051d9095f64c4cf681d03fc0be632ad074f1de80b06c4b6c

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