Skip to main content

async-ip-rotator

An async-first Python library that utilizes AWS API Gateway's large IP pool as a proxy to generate pseudo-infinite IPs for web scraping and automated requests. This is an async implementation inspired by requests-ip-rotator, rebuilt with httpx for modern async support.

This library allows you to bypass IP-based rate-limits for sites and services using async/await syntax.

X-Forwarded-For headers are automatically randomized and applied unless given. This is because otherwise, AWS will send the client's true IP address in this header.

AWS' ApiGateway sends its requests from any available IP - and since the AWS infrastructure is so large, it is almost guaranteed to be different each time. By using ApiGateway as a proxy, we can take advantage of this to send requests from different IPs each time. Please note that these requests can be easily identified and blocked, since they are sent with unique AWS headers (i.e. "X-Amzn-Trace-Id").

Installation

This package is on pypi so you can install via any of the following:

  • pip install async-aws-ip-rotator
  • python -m pip install async-aws-ip-rotator

Quick Start

import asyncio
import httpx
from async_ip_rotator import ApiGateway

async def main():
    # Create and use gateway with async context manager
    # Disable the default /ProxyStage path if needed to avoid changing signature for certain private endpoints
    async with ApiGateway("https://site.com", use_proxy_stage=False) as gateway:
        # Create async client with gateway
        async with httpx.AsyncClient(transport=gateway) as client:
            # Send request (IP will be randomized)
            response = await client.get("https://site.com/index.php", params={"theme": "light"})
            print(response.status_code)

asyncio.run(main())

Note: The gateway will automatically clean up its resources when the context manager exits.

Costs

API Gateway is free for the first million requests per region, which means that for most use cases this should be completely free. At the time of writing, AWS charges ~$3 per million requests after the free tier has been exceeded. If your requests involve data stream, AWS would charge data transfer fee at $0.09 per GB.

Documentation

AWS Authentication

It is recommended to setup authentication via environment variables. With awscli, you can run aws configure to do this, or alternatively, you can simply set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY variables yourself.

You can find your access key ID and secret by following the official AWS tutorial.

Creating ApiGateway object

The ApiGateway class can be created with the following optional parameters:

Name Description Required Default
site The site (without path) requests will be sent to True
regions An array of AWS regions to setup gateways in False DEFAULT_REGIONS
access_key_id AWS Access Key ID (will override env variables) False Relies on env variables
access_key_secret AWS Access Key Secret (will override env variables) False Relies on env variables
verbose Include status and error messages False True
use_proxy_stage Include '/ProxyStage' prefix in gateway URL (set False when not required) False True
from async_ip_rotator import ApiGateway, EXTRA_REGIONS, ALL_REGIONS

# Gateway to outbound HTTP IP and port for only two regions
gateway_1 = ApiGateway("http://1.1.1.1:8080", regions=["eu-west-1", "eu-west-2"])

# Gateway to HTTPS google for the extra regions pack, with specified access key pair
gateway_2 = ApiGateway(
    "https://www.google.com", 
    regions=EXTRA_REGIONS, 
    access_key_id="ID", 
    access_key_secret="SECRET"
)

Starting API gateway

The ApiGateway can be used as an async context manager, which will handle initialization and cleanup automatically:

# Using context manager (recommended)
async with ApiGateway("https://site.com") as gateway:
    # Gateway is ready to use here
    async with httpx.AsyncClient(transport=gateway) as client:
        response = await client.get("https://site.com/path")

# For manual control, you can still use start/shutdown methods
gateway = ApiGateway("https://site.com")
await gateway.start(force=True)  # force=True creates new endpoints even if some exist
# ... use gateway ...
await gateway.shutdown()

Sending Requests

Requests are sent using the httpx AsyncClient with the ApiGateway as transport:

async with httpx.AsyncClient(transport=gateway) as client:
    # Send request with random IP
    response = await client.get("https://site.com/path")
    
    # Send with custom X-Forwarded-For header
    response = await client.get(
        "https://site.com/path",
        headers={"X-Forwarded-For": "127.0.0.1"}
    )

Closing ApiGateway Resources

It's important to shutdown the ApiGateway resources once you have finished with them, to prevent dangling public endpoints that can cause excess charges to your account.

# Shutdown all gateways
await gateway.shutdown()

# Shutdown specific endpoints only
await gateway.shutdown(endpoints=["endpoint1", "endpoint2"])

Please note that any gateways started with require_manual_deletion=True will not be deleted via the shutdown method, and must be deleted manually through either the AWS CLI or Website.

Credit

This project is a fork of requests-ip-rotator by Ge0rg3, reimplemented with async support using httpx.

The core gateway creation and organisation code was adapted from RhinoSecurityLabs' IPRotate Burp Extension.

The X-My-X-Forwarded-For header forwarding concept was originally conceptualised by ustayready in his fireprox proxy.

Metadata

Release files for async-aws-ip-rotator 1.0.2

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

Source distribution (sdist)

Source distribution for async-aws-ip-rotator 1.0.2
File Size Uploaded Provenance Actions
async_aws_ip_rotator-1.0.2.tar.gz 19.8 kB Without provenance Details for async_aws_ip_rotator-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for async-aws-ip-rotator 1.0.2
File Interpreter ABI Platform Actions
async_aws_ip_rotator-1.0.2-py3-none-any.whl Python 3 none any Details for async_aws_ip_rotator-1.0.2-py3-none-any.whl

Total release size: 39.9 kB

Release files / async_aws_ip_rotator-1.0.2.tar.gz

Download URL async_aws_ip_rotator-1.0.2.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
af03c7bb1aeac9db1f22554acfce5face7514c5452e6fb0b23c1941688abd7f9
BLAKE2b-256 checksum
How to use checksums
cd59da57c27fee3fec0e6d6eff1f69034aee08e4360c19551c3cbfa87631dca5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / async_aws_ip_rotator-1.0.2-py3-none-any.whl

Download URL async_aws_ip_rotator-1.0.2-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60740a4324614360a0687c444128cf6572fd178ce99373dd00b4de47beca146f
BLAKE2b-256 checksum
How to use checksums
732db4f905bae331c07788a321c456dd374a15a6b0c57edf2156ec99256a4f98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.23

Security for async-aws-ip-rotator 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

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