Give AlbumentationsX a star on GitHub β€” it powers this leaderboard

Star on GitHub

niquests

Niquests is a simple, yet elegant, HTTP library. It is a drop-in replacement for Requests, which is under feature freeze.

Rank: #2859Downloads: 1,874,668 (30 days)Stars: 1,669Forks: 42

Description

<div align="center"> <img src="https://user-images.githubusercontent.com/9326700/282852138-160f32e9-e6cf-495f-b39d-99891602acf9.png" alt="Niquests Logo"/> </div>

Niquests is a simple, yet elegant, HTTP library. It is a drop-in replacement for Requests, which is under feature freeze. ✨ Were you used to betamax, requests-mock, responses, ...? See how they still work! We got you covered.

Niquests, is the β€œSafest, Fastest[^10], Easiest, and Most advanced” Python HTTP Client. Production Ready!

<div align="center"> <table> <tr> <td valign="middle"> <h3>Live Benchmark</h3> <b>Target:</b> <code>https://httpbingo.org/get</code><br/> <b>Conditions:</b> <i>All default parameters, one shared session, everything simultaneously.</i><br/> <b>HTTP/2</b> when supported. </td> <td> <img src="https://i.postimg.cc/CLxGykJL/niquests.gif" width="500" alt="Niquests Benchmark"/> </td> </tr> </table> </div> <details> <summary>πŸ‘† <b>Look at the feature table comparison</b> against <i>requests, httpx and aiohttp</i>!</summary>
Featureniquestsrequestshttpxaiohttp
HTTP/1.1βœ…βœ…βœ…βœ…
HTTP/2βœ…βŒβœ…[^7]❌
HTTP/3 over QUICβœ…βŒβŒβŒ
Synchronousβœ…βœ…βœ…N/A[^1]
Asynchronousβœ…βŒβœ…βœ…
Thread Safeβœ…βœ…βŒ[^5]N/A[^1]
Task Safeβœ…N/A[^2]βœ…βœ…
OS Trust Storeβœ…βŒβŒβŒ
Multiplexingβœ…βŒLimited[^3]❌
DNSSECβœ…[^11]❌❌❌
Customizable DNS Resolutionβœ…βŒβŒβœ…
DNS over HTTPSβœ…βŒβŒβŒ
DNS over QUICβœ…βŒβŒβŒ
DNS over TLSβœ…βŒβŒβŒ
Multiple DNS Resolverβœ…βŒβŒβŒ
Network Fine Tuning & Inspectβœ…βŒLimited[^6]Limited[^6]
Certificate Revocation Protectionβœ…βŒβŒβŒ
Session Persistenceβœ…βœ…βœ…βœ…
In-memory Certificate CA & mTLSβœ…βŒLimited[^4]Limited[^4]
SOCKS 4/5 Proxiesβœ…βœ…βœ…βŒ
HTTP/HTTPS Proxiesβœ…βœ…βœ…βœ…
TLS-in-TLS Supportβœ…βœ…βœ…βœ…
Direct HTTP/3 Negotiationβœ…[^9]N/A[^8]N/A[^8]N/A[^8]
Happy Eyeballsβœ…βŒβŒβœ…
Package / SLSA Signedβœ…βŒβŒβœ…
HTTP/2 with prior knowledge (h2c)βœ…βŒβœ…βŒ
Post-Quantum SecurityLimited[^12]❌❌❌
HTTP Trailersβœ…βŒβŒβŒ
Early Responsesβœ…βŒβŒβŒ
WebSocket over HTTP/1βœ…βŒ[^14]❌[^14]βœ…
WebSocket over HTTP/2 and HTTP/3βœ…[^13]❌❌❌
Automatic Ping for HTTP/2+βœ…N/A❌N/A
Automatic Connection Upgrade / Downgradeβœ…N/A❌N/A
Server Side Event (SSE)βœ…βŒβŒβŒ
</details> <details> <summary>πŸ“ˆ <b>Look at the performance comparison</b> against <i>them</i>!</summary>

Scenario: Fetch a thousand requests using 10 tasks or threads, each with a hundred requests using a single pool of connection.

High-Level APIs

ClientAverage Delay to CompleteNotes
requests987 ms or ~1013 req/sThreadPoolExecutor. HTTP/1.1
httpx720 ms or ~1389 req/sAsyncio. HTTP/2
niquests340 ms or ~2941 req/sAsyncio. HTTP/2

Simplified APIs

ClientAverage Delay to CompleteNotes
requests core643 ms or ~1555 req/sThreadPoolExecutor. HTTP/1.1
httpx core490 ms or ~2000 req/sAsyncio. HTTP/2
aiohttp210 ms or ~4762 req/sAsyncio. HTTP/1.1
niquests core160 ms or ~6200 req/sAsyncio. HTTP/2

Did you give up on HTTP/2 due to performance concerns? Think again! Do you realize that you can get 3 times faster with the same CPU if you ever switched to Niquests from Requests? Multiplexing and response lazyness open up a wide range of possibilities! Want to learn more about the tests? scripts? reasoning?

Take a deeper look at https://github.com/Ousret/niquests-stats

Update: The previous scenario is fairly complex to set up, and we were asked to provide a more "real life" benchmark scenario.

Given the script hosted at https://gist.github.com/Ousret/9e99b07e66eec48ccea5811775ec116d that simply execute 1k requests. We deliberately use two hosts, disabled Niquests manual multiplexing (for fairness), one known to be very slow (httpbin.org), and the other adequately fast (httpbingo.org) to showcase how the client behave.

Fast endpoint

ClientAverage Delay to CompleteNotes
httpx1.771sHTTP/1.1
aiohttp1.372sHTTP/2
niquests0.704sHTTP/2

Slow endpoint

ClientAverage Delay to CompleteNotes
httpx8.19sHTTP/1.1
aiohttp7.041sHTTP/2
niquests4.201sHTTP/2

:tada: Niquests can easily bring you twice the throughput if you migrated today. Join us today!

</details>
>>> import niquests
>>> r = niquests.get('https://one.one.one.one')
>>> r.status_code
200
>>> r.headers['content-type']
'application/json; charset=utf-8'
>>> r.oheaders.content_type.charset
'utf-8'
>>> r.encoding
'utf-8'
>>> r.text
'{"authenticated": true, ...'
>>> r.json()
{'authenticated': True, ...}
>>> r
<Response HTTP/2 [200]>
>>> r.ocsp_verified
True
>>> r.conn_info.established_latency
datetime.timedelta(microseconds=38)

or using async/await!

import niquests
import asyncio

async def main() -> None:
    r = await niquests.aget('https://one.one.one.one', stream=True)
    print(r)  # Output: <Response HTTP/2 [200]>
    payload = await r.text  # we await text because we set `stream=True`!
    print(payload)  # Output: <html>...
    # or... without stream=True
    r = await niquests.aget('https://one.one.one.one')
    print(r)  # Output: <Response HTTP/3 [200]>
    payload = r.text  # we don't need to away anything, it's already loaded!
    print(payload)  # Output: <html>...

asyncio.run(main())

Niquests allows you to send HTTP requests extremely easily. There’s no need to manually add query strings to your URLs, or to form-encode your PUT & POST data β€” just use the json method!

PyPI Downloads Supported Versions OpenSSF Best Practices

This project does not require any compilation toolchain. The HTTP/3 support is not enforced and installed if your platform can support it natively (e.g. pre-built wheel available).

✨ Installing Niquests and Supported Versions

Niquests is available on PyPI:

$ python -m pip install niquests

Niquests officially supports Python or PyPy 3.7+.

πŸš€ Supported Features & Best–Practices

Niquests is ready for the demands of building scalable, robust and reliable HTTP–speaking applications.

  • DNS over HTTPS, DNS ov