Skip to main content

Declarative HTTP client for Python

Project description

DeclarativeX

Description

DeclarativeX aims to make HTTP requests more declarative in Python. It uses Pydantic for data validation and Httpx for making the requests.

Installation

pip install declarativex

Usage

Here's a simple example:

from declarativex import BaseClient, get, Path


class MyClient(BaseClient):
    @get("/some/path{id}")
    def get_something(self, id: int = Path(...)) -> dict:
        pass


client = MyClient(base_url="https://example.com/")
client.get_something(id=42)

Async with pydantic example:

import asyncio

from declarativex import BaseClient, post, Json
from pydantic import BaseModel


class MyPydanticModel(BaseModel):
    name: str
    age: int


class AsyncPydanticClient(BaseClient):
    @post("/some/path")
    async def post_something(self, data: MyPydanticModel = Json(...)) -> MyPydanticModel:
        pass


client = AsyncPydanticClient(base_url="https://example.com/")
asyncio.run(client.post_something(MyPydanticModel(name="John", age=42))

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

declarativex-1.0.0.tar.gz (15.1 kB view hashes)

Uploaded Source

Built Distribution

declarativex-1.0.0-py3-none-any.whl (16.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page