Skip to main content

High-performance async HTTP client built with Rust for Python.

Project description

rusty-req

A high-performance asynchronous request library based on Rust + Python, suitable for scenarios that require batch HTTP requests. It implements concurrent request logic in Rust and packages it into a Python module using maturin , combining performance with ease of use.

🔧 Installation

pip install rusty-req

Or build from source:

maturin build --release
pip install target/wheels/rusty_req-*.whl

Development & Debugging

cargo watch -s "maturin develop"

🚀 Features

  • Batch asynchronous HTTP requests (supports GET / POST)
  • Customizable headers / params / timeout / tag
  • Global timeout control (total_timeout)
  • Returns response body, exception info, and meta data
  • Built with Rust + Tokio for high throughput

📦 Example Usage

import asyncio
import time
import rusty_req


async def main():
    # Using JSONPlaceholder - a free test API
    requests = [
        rusty_req.RequestItem(
            url="https://httpbin.org/delay/2",
            method="GET",
            headers={
                "Accept-Encoding": "gzip, deflate, br",
                "Connection": "keep-alive",
                "X-Test-Header": "ChatGPT"
            },
            timeout=2.9,
            tag=f"json-test-{i}",
        )
        for i in range(100)  # 100 concurrent requests
    ]

    # Disable debug logs
    rusty_req.set_debug(False)

    print("🚀 Starting 100 concurrent JSON API requests...")
    start_time = time.perf_counter()

    responses = await rusty_req.fetch_requests(
        requests,
        total_timeout=3.0
    )

    total_time = time.perf_counter() - start_time

    # Process results
    success = 0
    failed = 0
    status_codes = {}
    response_times = []

    for r in responses:
        if r.get("exception"):
            failed += 1
        else:
            meta = r.get("meta", {})
            status_code = meta.get("status_code", 0)
            process_time = float(meta.get("process_time", 0))

            status_codes[status_code] = status_codes.get(status_code, 0) + 1
            response_times.append(process_time)
            success += 1

    # Calculate metrics
    avg_response_time = sum(response_times) / len(response_times) if response_times else 0
    min_response_time = min(response_times) if response_times else 0
    max_response_time = max(response_times) if response_times else 0
    req_per_sec = success / total_time if total_time > 0 else 0

    print("\n📊 Load Test Summary:")
    print(f"⏱️ Total time: {total_time:.2f}s")
    print(f"📈 Requests per second: {req_per_sec:.1f}")
    print(f"✅ Successful requests: {success}")
    print(f"⚠️ Failed requests: {failed}")
    print(f"🔄 Status code distribution: {status_codes}")
    print(f"⏳ Response time - Avg: {avg_response_time:.4f}s, Min: {min_response_time:.4f}s, Max: {max_response_time:.4f}s")


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

🧱 数据结构说明

RequestItem Parameters

Field Type Required Description
url str Target URL
method str HTTP method ("GET" or "POST")
params dict / None No Query parameters (GET) or form data (POST)
headers dict / None No Custom HTTP headers
timeout float Timeout for a single request (in seconds)
tag str No Tag for tracing origin or indexing the request

Response Format

{
    "http_status": 200,
    "response": "{\"code\":403,\"msg\":\"Method Not Allowed.\"}",
    "meta": {
        "process_time": "0.2439",
        "request_time": "2025-07-29 19:17:11 -> 2025-07-29 19:17:11",
        "tag": "test-baidu1"
    },
    "exception": {
        "message": "HTTP status error: 500 - ", 
        "type": "HttpStatusError"
    }
}

📄 License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

rusty_req-0.2.6-cp312-cp312-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.12Windows x86-64

rusty_req-0.2.6-cp312-cp312-manylinux_2_28_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

rusty_req-0.2.6-cp312-cp312-macosx_10_12_universal2.whl (3.6 MB view details)

Uploaded CPython 3.12macOS 10.12+ universal2 (ARM64, x86-64)

rusty_req-0.2.6-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11Windows x86-64

rusty_req-0.2.6-cp311-cp311-manylinux_2_28_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

rusty_req-0.2.6-cp311-cp311-macosx_10_12_universal2.whl (3.6 MB view details)

Uploaded CPython 3.11macOS 10.12+ universal2 (ARM64, x86-64)

rusty_req-0.2.6-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10Windows x86-64

rusty_req-0.2.6-cp310-cp310-manylinux_2_28_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

rusty_req-0.2.6-cp310-cp310-macosx_10_12_universal2.whl (3.6 MB view details)

Uploaded CPython 3.10macOS 10.12+ universal2 (ARM64, x86-64)

rusty_req-0.2.6-cp39-cp39-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.9Windows x86-64

rusty_req-0.2.6-cp39-cp39-manylinux_2_28_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

rusty_req-0.2.6-cp39-cp39-macosx_10_12_universal2.whl (3.6 MB view details)

Uploaded CPython 3.9macOS 10.12+ universal2 (ARM64, x86-64)

File details

Details for the file rusty_req-0.2.6-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: rusty_req-0.2.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rusty_req-0.2.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fe0b1f991ec837ce8b921ab29b0e9a68014373106a367df5b7257d8e31944cd1
MD5 11ac620b7dc07950b641e3f0276b1636
BLAKE2b-256 f31ceaf2300b05c842c89133a808eddf0f839a31e53462fecbffe45224c66209

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rusty_req-0.2.6-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f3845baec044ff9a87a26945cfed5327180e566385110d30a2209fe1bdfdfaba
MD5 69ce5eaa343fd002dd9b934e7bea5548
BLAKE2b-256 d12256cd9c5a14b4b5ebf0047cca28ed09a641372aa8f4c3e76b7aecdcfb6af6

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp312-cp312-macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for rusty_req-0.2.6-cp312-cp312-macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 da5ff5f8fa8e03451091614762ab975934079fa137a78bf6920d797859a0ed96
MD5 f357eb62690127cc313b4948667c7daa
BLAKE2b-256 8a7c3a62811540a2042fbe96313bd3077cf2bbd8db2099f68f49aed65ae49ca3

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: rusty_req-0.2.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rusty_req-0.2.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 75b0d5dd967966725d57e17277e6e7190f3717cf83e4055bbb5f2eba50df0020
MD5 b8a9d49e72ec1ba0e5df529f931b409d
BLAKE2b-256 22a376dde27e56831b9d65e17b2a43ffca3ca2279601b2192d4e9648f69a00e0

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rusty_req-0.2.6-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d8ac6633e5afb47ad2c733fbc2e41d736dea5dff3b87db35a24240907130aa3d
MD5 21439fa890b65df819af56d264705370
BLAKE2b-256 5f915512e1d6be7bb0a102e95766f88ed198896041f23aa0dcdbdec0cd954453

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp311-cp311-macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for rusty_req-0.2.6-cp311-cp311-macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 37c03070b87f027358607ba50b0b43e11b745c27130d2172ec5d4523ce22534f
MD5 17c2f86dcef5375bc931ddcf004a62e2
BLAKE2b-256 1c03ee1c9a1e533662e6d0b55ed451af684552f7cfa08727a035d1b171bd3118

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: rusty_req-0.2.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rusty_req-0.2.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 32bc45fd0fc9d90ec2a7eddb169c7fb356ffd1fe362f70cb6926e1dec924953e
MD5 af208b6072158ab8704fe8fd2e41981d
BLAKE2b-256 b6f34248a18dd24f14634fcf8bda88a8990465f2c1d11ae87149400847490535

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rusty_req-0.2.6-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 482ea408b8ae6104fb8ff0d9b09c28adb0e194a2dc84d725122fb0d96504d6f0
MD5 2cf99ea0c3bfa4b62f9748b270f7c091
BLAKE2b-256 efc7fcc27f83959c374d96878b2c2a44c3e4ca4beb7a91399a72dfe8dd661a68

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp310-cp310-macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for rusty_req-0.2.6-cp310-cp310-macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 aaac2ed07b34d368a5d74c56c34aedf69bd617c1e79ee9b7470a8beb5ec13fea
MD5 03adbc3f8972ec22995ad8833d5dc297
BLAKE2b-256 5ba8e708e515e94c924cb803f1085542e9daa4c0280ac0d9b7df6beafb226317

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: rusty_req-0.2.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rusty_req-0.2.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e4ae31d2a240a21a03ce2b6cf90914a36ffc7af5b16f35b5023cb21805b24b42
MD5 aedcca4f2de7e75dcc757604a4272563
BLAKE2b-256 b2ccdf563bd0498453f7f6654cd51780bf788b23e17c6bf9b2c9e8090af3a452

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for rusty_req-0.2.6-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 31e01b88286789bb125ea20753b7be3cd1dec542c4c052a24ce76a32695bcd70
MD5 47e8761226cba21131834a25637a9728
BLAKE2b-256 5ef5c72633c0ef200392c4f90cc51d78424f2e6c65a75f364247e23ed687ff02

See more details on using hashes here.

File details

Details for the file rusty_req-0.2.6-cp39-cp39-macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for rusty_req-0.2.6-cp39-cp39-macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 69b70fa1414434d3746ea3043f5611fffc60d6fc9b4517a8281d0f3fd3d57de6
MD5 df34dbdcd90d3958f2500154e423158e
BLAKE2b-256 925828a9c99f5686b14f98165618b312f25fc16d1ccc3c0973073a21afcdae75

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