An HTTP API client for readable code
Project description
Tealeaf
A simple interface for readable Python HTTP clients
- No dependencies
- Simple and readable
- Lightweight
A simple example
import tealeaf
# simple POST
api = tealeaf.Api('https://www.postman-echo.com')
api.post('/post', {"message": "hello tealeaf"}).json()
# Using bearer tokens
api = tealeaf.Api(
'https://www.postman-echo.com',
credentials=tealeaf.BearerToken('my-jwt')
)
api.post('/post', {"message": "hello authorized tealeaf"}).json()
Integrates easily with pydantic
for data validation
import tealeaf
from pydantic import BaseModel
class Message(BaseModel):
message: str
class EchoResponse(BaseModel):
data: Message
url: str
# simple POST
api = tealeaf.Api('https://www.postman-echo.com')
echo = api \
.post('/post', {"message": "hello tealeaf"}) \
.astype(EchoResponse)
print(repr(echo))
>>> EchoResponse(data=Message(message='hello tealeaf'), url='https://www.postman-echo.com/post')
An example with custom auth algorithm:
# define a custom auth handler with a `preprocess_request` method
class CustomCredentialHandler(tealeaf.ApiCredential):
def __init__(self, secret: str):
super().__init__()
self.__secret = secret
def preprocess_request(self, request: tealeaf.Request):
# your algorithm goes here and modifies the request object
request.headers['secret-key'] = f'{request.data}{self.__secret}'
return request
api = tealeaf.Api(
'https://www.postman-echo.com',
credentials=CustomCredentialHandler('my-super-secret')
)
api.post('/post', {"message": "hello custom tealeaf auth"}).json()
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
tealeaf-0.0.9.tar.gz
(7.1 kB
view details)
Built Distribution
File details
Details for the file tealeaf-0.0.9.tar.gz
.
File metadata
- Download URL: tealeaf-0.0.9.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 621520b9f88f56155e51e97b35e2a26f7dddc7d8d1fa8cd0c90ad5b1253ad5b6 |
|
MD5 | 19b296f2f15d15c16c5cc58224e478c0 |
|
BLAKE2b-256 | 8f9cec1656a6a8e22e3253461c8da6415e6ed2df8bab7091428ce089e28ea2ad |
File details
Details for the file tealeaf-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: tealeaf-0.0.9-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ac2c0092938e98826869e4e81c057351357d5cf6758fe1013040f2f784672f6 |
|
MD5 | bc3d1aee3d6c98d491a9eb853caec711 |
|
BLAKE2b-256 | c117f95be46db3fc39f4293fa95243043c5b8903440909b3fbbb58fae1963cab |