Skip to main content

An HTTP API client for readable code

Project description

Tealeaf

license

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


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.5.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

tealeaf-0.0.5-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file tealeaf-0.0.5.tar.gz.

File metadata

  • Download URL: tealeaf-0.0.5.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for tealeaf-0.0.5.tar.gz
Algorithm Hash digest
SHA256 7db10a8c10e04ccf7ace0a2a1521358f3f5cb031e848b3fc5599d99626f6a439
MD5 f015cf41b05a64a590fc56582c20cb0e
BLAKE2b-256 ed1f2bfabcd362637098052b433a484e1dc513e530d3a51a5c5ff509c5f067ec

See more details on using hashes here.

File details

Details for the file tealeaf-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: tealeaf-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for tealeaf-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fb7031c964aa67cfc88baf8c8dfb1c7c430d2e0441efdb476ccd03610f682d84
MD5 76adce1eeb06ca593df6a902c44e41f3
BLAKE2b-256 1e13fbbc3b161dab74ecbddf670e8e7476e0165a4c32a40c23a60fe35a090607

See more details on using hashes here.

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