Skip to main content

aiohttpx

A Python Wrapper for httpx that combines the httpx.AsyncClient with the httpx.Client to allow both async and sync requests

Latest Version: PyPI version


Installation

# Install from pypi
pip install --upgrade aiohttpx

# Install from Github
pip install --upgrade git+https://github.com/trisongz/aiohttpx

Usage

aiohttpx is a wrapper around httpx that provides a unified async + sync interface for making HTTP requests. This is useful for making HTTP requests in both async and sync codebases.

Additionally, it includes a ProxyClient that can be used for scraping / high volume requests that would otherwise be blocked by the target server by using a rotating proxy pool through AWS API Gateway.

import asyncio

import aiohttpx

async def test_requests():
    # Notice it utilizes async context manager but can use sync methods.

    async with aiohttpx.Client() as client:
        # Make an Async GET request
        response = await client.async_get("https://httpbin.org/get")
        print(response.json())

        # Make a Sync GET request
        response = client.get("https://httpbin.org/get")
        print(response.json())
    
    # The same applies with the sync context manager
    with aiohttpx.Client() as client:
        # Make an Async GET request
        response = await client.async_get("https://httpbin.org/get")
        print(response.json())

        # Make a Sync GET request
        response = client.get("https://httpbin.org/get")
        print(response.json())


async def test_proxies():
    # Here we will test the ProxyClient
    # some magic/notes:
    
    # there is a wrapper for BeautifulSoup that is enabled for GET 
    # requests. This can be triggered by passing `soup_enabled=True` 
    # to the request method.
    
    # the ProxyClient will automatically terminate the api gateways upon 
    # exit from the context manager in both sync and async.

    # however if no context manager is used, then the ProxyClient will 
    # need to be manually terminated by calling 
    # `client.shutdown()` | `await client.async_shutdown()`

    # You can choose to perserve the api gateways by passing 
    # `reuse_gateways=True` to the ProxyClient constructor. 
    # This is useful if you want to reuse the same api gateways 
    # for multiple requests.

    # You can also increase the number of gateways per region to 
    # increase the number of concurrent requests. This can be done by 
    # passing `gateways_per_region=10` to the ProxyClient constructor.

    # by default the ProxyClient will use the `us-east-1` region. 
    # You can change this by passing `regions=["us-west-2"]` or 
    # `regions="us"` for all us regions to the ProxyClient constructor.


    base_url = "https://www.google.com"

    async with aiohttpx.ProxyClient(base_url = base_url) as client:
        # Make an Async GET request
        response = await client.async_get(
            "/search", 
            params = {"q": "httpx"},
            soup_enabled = True
        )
        print(response.soup)
        print(response.soup.title.text)

        # Make a Sync GET request
        response = client.get(
            "/search", 
            params = {"q": "httpx"},
            soup_enabled = True
        )
        print(response.soup)
        print(response.soup.title.text)
    
    # Upon exiting the context manager, the api gateways will be terminated.


async def run_tests():
    await asyncio.gather(
        test_requests(),
        test_proxies()
    )

asyncio.run(run_tests())

Metadata

Release files for aiohttpx 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiohttpx 0.0.12
File Size Uploaded
aiohttpx-0.0.12.tar.gz 27.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiohttpx 0.0.12
File Interpreter ABI Platform
aiohttpx-0.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 59.5 kB

Release files / aiohttpx-0.0.12.tar.gz

Download URL aiohttpx-0.0.12.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bf109259868eacdb51d53e093042a72f889ead9ba518e21b1bac84e3579faf16
BLAKE2b-256 checksum
How to use checksums
f3b441723401020e236496a7156247d927ce9001b56f96d16b0b5c5708072289
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / aiohttpx-0.0.12-py3-none-any.whl

Download URL aiohttpx-0.0.12-py3-none-any.whl
Size 31.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f75fbaeb149f890905b2c0f86b1901db8b626407bef6d7f2b1cf29d5887656f1
BLAKE2b-256 checksum
How to use checksums
8ff743ed411ef2bf1f0c6981c5effe83199e2101385e246ad5762a6667828f34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.0.12 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page