Skip to main content

Fast and simple HTTP client library with async support and beautiful logging

Project description

GitHub stars GitHub forks GitHub watchers

httpx ruff mypy Python License CodSpeed

Features

  • Simple API - Minimal boilerplate with decorators
  • Beautiful Logging - Colorful request/response logs with timing
  • Async Support - Built on httpx for high performance
  • Type Safe - Full type annotations with Pydantic support
  • All HTTP Methods - GET, POST, PUT, PATCH, DELETE
  • Middleware - Request/response interception and modification
  • Rate Limiting - Multiple strategies (token bucket, leaky bucket, etc.)
  • HTTP/2 Support - Optional HTTP/2 protocol support
  • Request Info - Access to request details from response object

Quick Start

Installation

pip install fasthttp-client

Basic Usage

from fasthttp import FastHTTP
from fasthttp.response import Response

app = FastHTTP()


@app.get(url="https://httpbin.org/get")
async def get_data(resp: Response):
    return resp.json()


if __name__ == "__main__":
    app.run()

Output:

16:09:18.955 │ INFO     │ fasthttp │ ✔ FastHTTP started
16:09:19.519 │ INFO     │ fasthttp │ ✔ ← GET https://httpbin.org/get [200] 458.26ms
16:09:20.037 │ INFO     │ fasthttp │ ✔ Done in 1.08s

HTTP/2 Support

Enable HTTP/2 for better performance with servers that support it:

from fasthttp import FastHTTP
from fasthttp.response import Response

app = FastHTTP(http2=True)

@app.get(url="https://www.google.com/")
async def get_google(resp: Response):
    print(f"Status: {resp.status}")
    return resp.status

if __name__ == "__main__":
    app.run()

Note: Install with pip install fasthttp-client[http2] for HTTP/2 support. HTTP/2 works with servers like Google, GitHub, YouTube, and many others. Servers that don't support HTTP/2 will automatically fall back to HTTP/1.1.

Middleware

Add custom logic to requests and responses:

from fasthttp import FastHTTP
from fasthttp.middleware import BaseMiddleware
from fasthttp.response import Response
from fasthttp.routing import Route
from fasthttp.types import RequestsOptinal

class LoggingMiddleware(BaseMiddleware):
    async def before_request(
        self, route: Route, config: RequestsOptinal
    ) -> RequestsOptinal:
        print(f"Sending {route.method} to {route.url}")
        return config

app = FastHTTP(middleware=[LoggingMiddleware()])

@app.get(url="https://api.example.com/data")
async def get_data(resp: Response) -> dict:
    return resp.json()

if __name__ == "__main__":
    app.run()

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

fasthttp_client-1.2.6.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fasthttp_client-1.2.6-py3-none-any.whl (71.7 kB view details)

Uploaded Python 3

File details

Details for the file fasthttp_client-1.2.6.tar.gz.

File metadata

  • Download URL: fasthttp_client-1.2.6.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for fasthttp_client-1.2.6.tar.gz
Algorithm Hash digest
SHA256 e8faf1e849b2a1eaf24efea7942737a7b6fd1bf67c2cded5b07e89cce00ad88f
MD5 725201a2b1f3e1f54ff035f6a687d410
BLAKE2b-256 d605f6913e3609be7fb2efdcc9059e0cbcac1e068262c67ac738da8c96bec1a6

See more details on using hashes here.

File details

Details for the file fasthttp_client-1.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for fasthttp_client-1.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b4667679269455be2d3b0138c6c118b73173d48be2b961d41234dfc192b4fd9a
MD5 1cccbc67e4926d72dda4269e7b389355
BLAKE2b-256 a3d441fe9c41b263133dc558f6945f385f513af3de61203640145a9d0cfe6acf

See more details on using hashes here.

Supported by

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