Skip to content

AYMENJD/redc

Repository files navigation

RedC logo

Async HTTP client for Python with native libcurl performance.

PyPI version Curl version Build status Python versions Downloads

Features

  • Protocols: Supports HTTP/1.1, HTTP/2, and HTTP/3
  • curl-powered: Built on top of libcurl for performance and reliability
  • Streaming: Efficient handling of large responses
  • Proxying: Simple and flexible proxy configuration
  • Google CA Trust: Uses trustifi as the default TLS trust store

Installation

You can install RedC via pip:

pip install redc

Quick Start

import asyncio
from redc import Client

async def main():
    async with Client(base_url="https://jsonplaceholder.typicode.com") as client:
        # Make a GET request
        response = await client.get("/posts/1")
        response.raise_for_status()
        print(response.status_code)  # 200
        print(response.json())  # {'userId': 1, 'id': 1, 'title': '...', 'body': '...'}

        # Make a POST request with JSON data
        response = await client.post(
            "/posts",
            json={"title": "foo", "body": "bar", "userId": 1},
        )
        response.raise_for_status()
        print(response.status_code)  # 201
        print(response.json())  # {'id': 101, ...}

asyncio.run(main())

URL Utilities

RedC includes a high-performance URL parser powered by libcurl.

from redc import CurlURL

u = CurlURL("https://user:pass@example.com:8080/path?q=1#frag")

print(u.host)   # example.com
print(u.port)   # 8080
print(u.path)   # /path

u.query = None
u["port"] = 443

print(str(u))
# https://user:pass@example.com:443/path#frag

Validate URLs:

from redc import CurlURL

print(CurlURL.is_valid_url("https://example.com"))  # True
print(CurlURL.is_valid_url("::::invalid::::"))      # False

License

MIT LICENSE

About

High-performance, asynchronous HTTP client in Python, driven by libcurl

Topics

Resources

License

Stars

Watchers

Forks

Contributors