Impit (Python)

0.12.0 · active · verified Sat Apr 11

Impit is a high-performance Python library that provides bindings for a Rust-based HTTP client, enabling browser-like TLS fingerprints, automatic HTTP header ordering, and support for HTTP/2 and HTTP/3. It offers an API similar to popular Python HTTP libraries like httpx and requests, making it suitable for web scraping and applications requiring advanced browser impersonation to avoid detection. The current version is 0.12.0, with an active release cadence for both its Python and Node.js bindings.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an `AsyncClient` and make an asynchronous GET request, mimicking a Firefox browser. It highlights common client configuration options and basic response handling. Remember to close the client using `await client.aclose()` to release resources.

import asyncio
from impit import AsyncClient

async def main():
    # Initialize AsyncClient with browser impersonation settings
    # Options for 'browser': 'chrome', 'firefox'
    # http3=True enables HTTP/3 support
    client = AsyncClient(http3=True, browser='firefox')

    # Make an asynchronous GET request
    try:
        response = await client.get("https://example.com")
        response.raise_for_status() # Raise an exception for bad status codes
        print(f"Status Code: {response.status_code}")
        print(f"HTTP Version: {response.http_version}")
        print("Response content (first 200 chars):\n" + response.text[:200])
    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        await client.aclose() # Ensure the client is closed

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →