Skip to main content

An HTTP API client for readable code

Project description

Tealeaf

A simple interface for readable Python HTTP clients

  • No dependencies
  • Simple and readable
  • Lightweight

import json
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()

# 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.1.tar.gz (5.8 kB view hashes)

Uploaded Source

Built Distribution

tealeaf-0.0.1-py3-none-any.whl (4.7 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