-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace requests with niquests, and drop support for Python 3.6.
- Loading branch information
Showing
59 changed files
with
3,951 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,31 @@ grafana.organization.create_organization( | |
organization={"name": "new_organization"}) | ||
``` | ||
|
||
Or using asynchronous code... the interfaces are identical except for the fact that you will handle coroutines (async/await). | ||
|
||
```python | ||
from grafana_client import AsyncGrafanaApi | ||
import asyncio | ||
|
||
async def main(): | ||
# Connect to Grafana API endpoint using the `GrafanaApi` class | ||
grafana = AsyncGrafanaApi.from_url("https://username:[email protected]/grafana/") | ||
|
||
# Create user | ||
user = await grafana.admin.create_user({ | ||
"name": "User", | ||
"email": "[email protected]", | ||
"login": "user", | ||
"password": "userpassword", | ||
"OrgId": 1, | ||
}) | ||
|
||
# Change user password | ||
user = await grafana.admin.change_user_password(2, "newpassword") | ||
|
||
asyncio.run(main()) | ||
``` | ||
|
||
### Example programs | ||
|
||
There are complete example programs to get you started within the [examples | ||
|
@@ -133,7 +158,7 @@ grafana = GrafanaApi.from_env() | |
``` | ||
|
||
Please note that, on top of the specific examples above, the object obtained by | ||
`credential` can be an arbitrary `requests.auth.AuthBase` instance. | ||
`credential` can be an arbitrary `niquests.auth.AuthBase` instance. | ||
|
||
## Selecting Organizations | ||
|
||
|
@@ -166,14 +191,24 @@ scalar `float` value, or as a tuple of `(<read timeout>, <connect timeout>)`. | |
|
||
## Proxy | ||
|
||
The underlying `requests` library honors the `HTTP_PROXY` and `HTTPS_PROXY` | ||
The underlying `niquests` library honors the `HTTP_PROXY` and `HTTPS_PROXY` | ||
environment variables. Setting them before invoking an application using | ||
`grafana-client` has been confirmed to work. For example: | ||
``` | ||
export HTTP_PROXY=10.10.1.10:3128 | ||
export HTTPS_PROXY=10.10.1.11:1080 | ||
``` | ||
|
||
## DNS Resolver | ||
|
||
`niquests` support using a custom DNS resolver, like but not limited, DNS-over-HTTPS, and DNS-over-QUIC. | ||
You will have to set `NIQUESTS_DNS_URL` environment variable. For example: | ||
``` | ||
export NIQUESTS_DNS_URL="doh+cloudflare://" | ||
``` | ||
|
||
See the [documentation](https://niquests.readthedocs.io/en/latest/user/quickstart.html#set-dns-via-environment) to learn | ||
more about accepted URL parameters and protocols. | ||
|
||
## Details | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
About | ||
===== | ||
Example program for listing folders and getting a dashboard of a remote Grafana | ||
instance. By default, it uses `play.grafana.org`. Please adjust to your needs. | ||
Synopsis | ||
======== | ||
:: | ||
source .venv/bin/activate | ||
python examples/folders-dashboard.py | jq | ||
""" | ||
|
||
import asyncio | ||
import json | ||
import sys | ||
from time import perf_counter | ||
|
||
from grafana_client import AsyncGrafanaApi | ||
|
||
|
||
async def fetch_dashboard(grafana, uid): | ||
print(f"## Dashboard with UID {uid} at play.grafana.org", file=sys.stderr) | ||
dashboard = await grafana.dashboard.get_dashboard(uid) | ||
print(json.dumps(dashboard, indent=2)) | ||
|
||
|
||
async def main(): | ||
before = perf_counter() | ||
# Connect to public Grafana instance of Grafana Labs fame. | ||
grafana = AsyncGrafanaApi(host="play.grafana.org") | ||
|
||
print("## All folders on play.grafana.org", file=sys.stderr) | ||
folders = await grafana.folder.get_all_folders() | ||
print(json.dumps(folders, indent=2)) | ||
|
||
tasks = [] | ||
|
||
for folder in folders: | ||
if folder["id"] > 0: | ||
tasks.append(fetch_dashboard(grafana, folder["uid"])) | ||
if len(tasks) == 4: | ||
break | ||
|
||
await asyncio.gather(*tasks) | ||
print(f"## Completed in {perf_counter() - before}s", file=sys.stderr) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.