Http client base pydantic, with requests or aiohttp
Project description
pydantic-client
Http client base pydantic, with requests or aiohttp
How to install
-
only support requests:
pip install pydantic-client
-
support aiohttp and requests:
pip install pydantic-client[aiohttp]
-
support httpx and requests:
pip install pydantic-client[httpx]
-
support all:
pip install pydantic-client[all]
How to use
from pydantic import BaseModel
from pydantic_client import delete, get, post, put
from pydantic_client.clients.requests import RequestsClient
class Book(BaseModel):
name: str
age: int
class R(RequestsClient):
@get("/books/{book_id}?query={query}")
def get_book(self, book_id: int, query: str) -> Book:
...
@post("/books", form_body=True)
def create_book_form(self, book: Book) -> Book:
""" will post the form with book"""
...
@put("/books/{book_id}")
def change_book(self, book_id: int, book: Book) -> Book:
"""will put the json body"""
...
@delete("/books/{book_id}")
def change_book(self, book_id: int) -> Book:
...
my_client = R("http://localhost/v1")
get_book: Book = my_client.get_book(1)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydantic_client-0.1.11.tar.gz
(8.5 kB
view hashes)
Built Distribution
Close
Hashes for pydantic_client-0.1.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 395d1fc8ec26ffc3d5b688fd123efa206183023d7927f0d69602980c448cb0e1 |
|
MD5 | 2fc343823420549e4bb80b07fa33b640 |
|
BLAKE2b-256 | e192d0d530f8c2e910a9df19fbb44c5925420e01dcc8882a01d290a433bc0844 |