Grafana Client migrated from Requests to Niquests

Feature Request :bookmark_tabs:

Recently, there was a feature request by Andrea Ghensi about adding async support to the grafana-client library we are maintaining.

feature request: async api · Issue #134 · panodata/grafana-client · GitHub

Patch Landed :sparkles:

Now, Ahmed Tahri submitted a patch to use the Niquests library as a drop-in replacement to the Requests library, and we just released grafana-client 4.0.0 including that patch.

feat: add async support by Ousret · Pull Request #146 · panodata/grafana-client · GitHub

We haven’t received any complaints from the community up until now, so we consider this to be a successful operation so far. Thank you so much for your contribution, Ahmed, and also for your request, Andrea.

Summary :mega:

Niquests is a wonderful drop-in package for Requests, if you need to have async HTTP conversations. Enumerated below in the »Backlog« section, there are a few hiccups we observed on the migration of grafana-client and grafana-wtf, but nothing serious. You are doing an excellent job there, Ahmed. Good luck for Niquests, and keep up the good work. :100:

Trivia :bulb:

Download numbers

Now a dependency of grafana-client, download numbers will also significantly raise on the niquests package.


Date 3.5.5
2024-03-30 1,164
2024-03-29 1,297
2024-03-28 69
2024-03-27 217
2024-03-26 67
2024-03-25 257
2024-03-24 0
2024-03-23 0
2024-03-22 0

niquests download stats


We discovered a few spots which could be improved on behalf of the Niquests library, or its documentation. On the other hand, maybe we just did not read it properly, so please bear with us.

Compatibility with requests-cache

Was slightly struggling to make requests-cache work again, also because of bad code quality of grafana-wtf. With support by Ahmed, the code in does the trick. Maybe it is advisable to demonstrate that snippet at Recommended Packages and Extensions - Niquests 3.5.5 documentation.

Request cache stopped working? · Issue #132 · panodata/grafana-wtf · GitHub

requests-mock & custom matchers

Does not work with custom matchers of requests-mock out of the box, but would need adjustments. Maybe API compatibility or docs can be improved?

Add support for Grafana library elements by amotl · Pull Request #168 · panodata/grafana-client · GitHub

Unclear error message

… on processing failures, when Niquests is accidentally used together with elements from Requests, like requests.adapters.HTTPAdapter.

TypeError: expected string or bytes-like object

Problem with grafana-client 4.0.0: `TypeError: expected string or bytes-like object` · Issue #126 · panodata/grafana-wtf · GitHub

Monkeypatching requests

Q: Provide the bootstrapping code by the library itself already?
A: It would not be wise outside of a development environment.


So that code like this:

from sys import modules

import niquests
import urllib3

# Amalgamate the module namespace to make all modules aiming
# to use `requests`, in fact use `niquests` instead.
modules["requests"] = niquests
modules["requests.adapters"] = niquests.adapters
modules["requests.sessions"] = niquests.sessions
modules["requests.exceptions"] = niquests.exceptions
modules["requests.packages.urllib3"] = urllib3

can effectively be compressed into that:

from niquests import monkey

SQLite cache: Use `requests_cache.CachedSession` for better concurrency by amotl · Pull Request #130 · panodata/grafana-wtf · GitHub


In cases where it might be unclear, we will be happy to provide more details, for example reproducers how we have been able to run into corresponding situations.

Alternatively to this enumeration, we may also file dedicated issues at the issue tracker of the upstream project GitHub - jawah/niquests: Requests but with HTTP/3, HTTP/2, Multiplexed Connections, System CAs, Certificate Revocation, DNS over HTTPS / TLS / QUIC or UDP, Async, DNSSEC, and (much) pain removed!. However, this needs more effort than just taking notes about them, so here we are.

grafana-wtf 0.19.0 has been released, concluding the update to Niquests, through grafana-client 4.0.0. Cheers!

UX improvements about a few items outlined above have been implemented by 🎨 Better UX for users migrating off Requests by Ousret · Pull Request #104 · jawah/niquests · GitHub, and will be part of the next release. Thank you again, Ahmed.