Niquests HTTP Library
Niquests is a simple, yet elegant, HTTP library designed as a drop-in replacement for Requests, which is currently under feature freeze. It aims to extend Requests' capabilities with modern features like async support, ASGI/WSGI integration, and experimental WebAssembly compatibility. The current version is 3.18.5, and it maintains an active release cadence with frequent updates.
Warnings
- gotcha While Niquests is a drop-in replacement for Requests, subtle behavioral differences may exist. For instance, the default `keepalive_delay` was lowered from 1 hour to 10 minutes in v3.18.3, which can affect long-lived connections.
- gotcha Compatibility issues for `isinstance` checks relying on `niquests.packages` were present in earlier versions, leading to potential type-checking failures. This was fixed in v3.18.4, but suggests reliance on internal `requests`-like structure can be brittle.
- gotcha Experimental features like WebAssembly (WASM) support introduced in v3.18.0 require specific environments (e.g., Chrome v137+, Firefox v131+, Node v22+) and often require enabling JavaScript Promise Integration (JSPI) explicitly.
- gotcha Advanced features such as the `rtls` alternative TLS backend (v3.18.3) or native `http+unix` connections (v3.17.0) may require additional `pip install` dependencies or specific environmental configurations beyond the basic `niquests` install.
Install
-
pip install niquests
Imports
- get
import niquests response = niquests.get('https://httpbin.org/get') - post
import niquests response = niquests.post('https://httpbin.org/post', json={'key': 'value'}) - Session
from niquests import Session session = Session()
- AsyncSession
from niquests import AsyncSession async_session = AsyncSession()
Quickstart
import niquests
import asyncio
def sync_example():
print('--- Sync Example ---')
response = niquests.get('https://httpbin.org/get')
response.raise_for_status()
print(f"Sync GET status: {response.status_code}")
print(f"Sync GET JSON: {response.json()['headers']['Host']}")
async def async_example():
print('\n--- Async Example ---')
async with niquests.AsyncSession() as session:
response = await session.post('https://httpbin.org/post', json={'test': 'data'})
response.raise_for_status()
print(f"Async POST status: {response.status_code}")
print(f"Async POST JSON: {response.json()['json']}")
if __name__ == '__main__':
sync_example()
asyncio.run(async_example())