Skip to content
/ rnet Public

Asynchronous Python HTTP Client with Black Magic

License

Notifications You must be signed in to change notification settings

0x676e67/rnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rnet

CI PyPI - License PyPI Python Version from PEP 621 TOML

🚀 Help me work seamlessly with open source sharing by sponsoring me on GitHub

An asynchronous Python HTTP client with Black Magic, powered by FFI from rquest, capable of mimicking TLS and HTTP2 fingerprints of popular browsers like Chrome, Safari, Firefox, and OkHttp.

Features

  • Plain, Form, JSON, urlencoded
  • Header Order
  • Redirect Policy
  • Cookie Store
  • HTTP Proxies
  • Async DNS Resolver
  • WebSocket Upgrade
  • HTTPS via BoringSSL

Example

This asynchronous example demonstrates how to make a simple GET request using the rnet library. So you need install rnet and run the following code:

pip install rnet

And then the code:

import asyncio
from rnet import Impersonate, Client


async def main():
    client = Client(
        impersonate=Impersonate.Firefox135,
        user_agent="rnet",
    )
    resp = await client.get("https://tls.peet.ws/api/all")
    print("Status Code: ", resp.status_code)
    print("Version: ", resp.version)
    print("Response URL: ", resp.url)
    print("Headers: ", resp.headers)
    print("Encoding: ", resp.encoding)
    print("Content-Length: ", resp.content_length)
    print("Remote Address: ", resp.remote_addr)
    print(await resp.text())


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

Additional learning resources include:

Platforms

  1. Linux
  • musl: x86_64, aarch64, armv7, i686
  • glibc >= 2.17: x86_64
  • glibc >= 2.31: aarch64, armv7, i686
  1. macOS: x86_64,aarch64

  2. Windows: x86_64,i686

Impersonate

In fact, most device models have the same TLS/HTTP2 configuration, except that the User-Agent is changed.

  • Chrome

Chrome100, Chrome101, Chrome104, Chrome105, Chrome106, Chrome107, Chrome108, Chrome109, Chrome114, Chrome116, Chrome117, Chrome118, Chrome119, Chrome120, Chrome123, Chrome124, Chrome126, Chrome127, Chrome128, Chrome129, Chrome130, Chrome131, Chrome133

  • Edge

Edge101, Edge122, Edge127, Edge131

  • Safari

SafariIos17_2, SafariIos17_4_1, SafariIos16_5, Safari15_3, Safari15_5, Safari15_6_1, Safari16, Safari16_5, Safari17_0, Safari17_2_1, Safari17_4_1, Safari17_5, Safari18, SafariIPad18, Safari18_2, Safari18_1_1

  • OkHttp

OkHttp3_9, OkHttp3_11, OkHttp3_13, OkHttp3_14, OkHttp4_9, OkHttp4_10, OkHttp5

  • Firefox

Firefox109, Firefox117, Firefox128, Firefox133, Firefox135, FirefoxPrivate135, FirefoxAndroid135

Building

  1. Install environment
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
pip install maturin
pip install uv

uv venv
source .venv/bin/activate
  1. Development
maturin develop --uv
python3 examples/client.py
  1. Compile wheels
  • Local Compilation

You need to install the BoringSSL build environment. You can refer to boring-ci and boringssl.

maturin build --release
  • Musllinux

You also need to install the Docker environment. The image might be outdated, so if you need to build the image yourself, refer to rust-cross-musl and the upstream rust-cross-musl. The upstream rust-cross-musl lacks the relevant platform linker environment variables, which you need to add yourself.

bash .github/musl_build.sh x86_64-unknown-linux-musl
bash .github/musl_build.sh aarch64-unknown-linux-musl
bash .github/musl_build.sh armv7-unknown-linux-musleabihf
bash .github/musl_build.sh i686-unknown-linux-musl
  • Manylinux

For Manylinux compilation, refer to manylinux.

Documentation

The python documentation is automatically supported by pyo3-stub-gen. It is not perfect. If you have any suggestions, you can submit a PR to improve it.

Contributing

If you would like to submit your contribution, please open a Pull Request.

Getting help

Your question might already be answered on the issues

License

rnet © 0x676e67, Released under the GPL-3.0 License.