Skip to main content

A lightweight, high concurrency HTTP request library

Project description

reqrio is an HTTP request library designed for fast, simple, and convenient HTTP request usage.

  • Features: Low copy, high concurrency, low overhead

  • Supports TLS fingerprinting, which can be configured via hexadecimal, Ja3, or Ja4 TLS handshake settings (* subscription only*).

  • Ensures request header order (see Request Header Order Table), consistent with browsers.

  • Uses BoringSSL to implement TLS, consistent with browsers like Chrome and Edge.

Low-Copy

reqrio is a low copy request sending engine used to efficiently encrypt user or file data over TLS and send it to TCP. reqrio Convert user input data such as form data, json, bytes, text, etc. into bytes for storage, and only copy once during TLS encryption, while only the data is processed in other stages Borrow (borrowing). File uploads are read through into_deader to reduce memory overhead

        Form  ┌────────┐encode->bytes ┌──────────┐             ┌──────────┐
 User ───────►│        │─────────────►│          │             │          │
        Json  │ ScReq  │  into_bytes  │  Request │ copy slice  │ fragment │ write ┌───────┐
              │ AcReq  │              │  borrow  │────────────►│  TLS     │──────►│  TCP  │
       Files  │(Engine)│ into_reader  │  reader  │             │ Encrypt  │       └───────┘
 User ───────►│        │─────────────►│          │             │          │
              └────────┘              └──────────┘             └──────────┘

Request Header Order Table

No. HTTP/2.0 HTTP/1.1
1 cache-control Host
2 sec-ch-ua Connection
3 sec-ch-ua-mobile Content-Length
4 sec-ch-ua-full-version Authorization
5 sec-ch-ua-arch Content-Type
6 sec-ch-ua-platform Cache-Control
7 sec-ch-ua-platform-version sec-ch-ua
8 sec-ch-ua-model sec-ch-ua-mobile
9 sec-ch-ua-bitness sec-ch-ua-platform
10 sec-ch-ua-full-version-list Upgrade-Insecure-Requests
11 upgrade-insecure-requests User-Agent
12 user-agent Accept
13 accept Sec-Fetch-Site
14 origin Sec-Fetch-Mode
15 sec-fetch-site Sec-Fetch-User
16 sec-fetch-mode Sec-Fetch-Dest
17 sec-fetch-user Sec-Fetch-Storage-Access
18 sec-fetch-dest Referer
19 sec-fetch-storage-access Accept-Encoding
20 referer Accept-Language
21 accept-encoding Cookie
22 accept-language Origin
23 cookie
24 priority
//unknown
25 content-encoding
26 content-type
27 authorization
28 content-type

Usage Example:

import reqrio

# The default is to use http/1.1
# * If the same session uses the same TCP connection, it will automatically reconnect upon disconnection.
session = reqrio.Session(alpn=reqrio.ALPN.HTTP20)
headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "Accept-Encoding": "gzip, deflate, br, zstd",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
    "Cache-Control": "no-cache",
    "Connection": "keep-alive",
    # "Cookie": "__guid=15015764.1071255116101212729.1764940193317.2156; env_webp=1; _S=pvc5q7leemba50e4kn4qis4b95; QiHooGUID=4C8051464B2D97668E3B21198B9CA207.1766289287750; count=1; so-like-red=2; webp=1; so_huid=114r0SZFiQcJKtA38GZgwZg%2Fdit1cjUGuRcsIL2jTn4%2FE%3D; __huid=114r0SZFiQcJKtA38GZgwZg%2Fdit1cjUGuRcsIL2jTn4%2FE%3D; gtHuid=1",
    # "Host": "m.so.com",It's best not to manually set the host value; let the underlying system automatically add it to avoid host conflicts when using different connections within the same session.
    "Pragma": "no-cache",
    "Sec-Fetch-Dest": "document",
    "Sec-Fetch-Mode": "navigate",
    "Sec-Fetch-Site": "none",
    "Sec-Fetch-User": "?1",
    "Upgrade-Insecure-Requests": 1,
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0",
    "sec-ch-ua": '"Microsoft Edge";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": '"Windows"'
}
# By default, there are no request headers; you need to configure them yourself.
session.set_header_json(headers)
# Set timeout
session.set_timeout(3000, 3000, 3000, 3000)
resp = session.get('https://m.so.com')
# Get response headers
print(resp.header.__dict__)
# Get the response body
print(resp.text())
# Try decoding to JSON
print(resp.json())

# Here, instead of establishing a new connection, the previous TCP connection is reused.
stream = session.open_stream('https://m.so.com/', reqrio.Method.GET)
for bs in stream:
    # Processing data streams
    print(len(bs))
# Get the returned response headers
print(stream.response.header.__dict__)

# Close the connection resource, remember to call...
session.close()
  • Websocket Example
from reqrio import WebSocket, WsOpCode

headers = {
    'Origin': 'https://xxx.com',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0',
    'Cookie': "pac_uid=0_NattYaCs7NNmH; omgid=0_NattYaCs7NNmH; _qimei_uuid42=19c1f11150d1000f92fe16d850a9c40cf94ef1d39f; _qimei_fingerprint=f3dc39297e432b1f08da57e9904a8f52; _qimei_q36=; _qimei_h38=a549811f92fe16d850a9c40c02000006b19c1f; _qpsvr_localtk=0.2296543129537577; RK=WPZCq/wl3I; ptcz=c338dead622f05f0d8467ac10589e7e45326b81d67ff476b9643f933cfdc644a; eas_sid=M1b7q677w9D5R5P2L8x5g4p313; eas_entry=https%3A%2F%2Fgraph.qq.com%2F; POESESSID=939e23af876572a0b2852b2e183e20cc"
}
ws = WebSocket(
    'wss://xxx.com/',
    uri="wss://xxx.com/api/trade2/live/poe2/%E7%93%A6%E5%B0%94%E7%9A%84%E5%AE%BF%E5%91%BD/32Y6Wjkc5",
    headers=headers)
ws.open()
while True:
    frame = ws.read()
    print(frame.opcode, WsOpCode.PING, frame.opcode == WsOpCode.PING)
    if frame.opcode == WsOpCode.PING:
        print("ping")
        ws.write(WsOpCode.PONG, frame.payload)
    else:
        print(frame.payload.decode('utf-8'))

Project details


Download files

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

Source Distribution

reqrio-0.3.0a4.tar.gz (3.6 MB view details)

Uploaded Source

Built Distribution

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

reqrio-0.3.0a4-py3-none-any.whl (3.6 MB view details)

Uploaded Python 3

File details

Details for the file reqrio-0.3.0a4.tar.gz.

File metadata

  • Download URL: reqrio-0.3.0a4.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for reqrio-0.3.0a4.tar.gz
Algorithm Hash digest
SHA256 507cca650c0305aeb48edb5f681fb962e2593b85171dc4c0a6556b453d0347d8
MD5 81bb3a2e69aa1e35353221754eff25b4
BLAKE2b-256 a0d8551872339804d342b40005d16382d19734dea805baa32e5a818c9e0273b5

See more details on using hashes here.

File details

Details for the file reqrio-0.3.0a4-py3-none-any.whl.

File metadata

  • Download URL: reqrio-0.3.0a4-py3-none-any.whl
  • Upload date:
  • Size: 3.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for reqrio-0.3.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 3a0deba3d923901a751cfe39ec0dd709a749f142c8d04d7a8e8095775260cb97
MD5 c256f1bdbe1bcd03a68429e01b876edc
BLAKE2b-256 456310c3374926f19cceb89c806d18b37e09404f0795195dd1f5c0ad25cec90d

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