Client utilities to interact with next layer public APIs
Project description
nextlayer-sdk-python
Client utilities to interact with next layer public APIs.
Configuration
The module will use a YAML Config file to read it's configuration and also writes to it,
to store obtained Tokens and their expiry (similar like kubctl does with kubeconfig).
Example ~/.nextlayer-sdk/auth.nlcustomers.yml:
server_url: https://login.nextlayer.at/auth/
realm_name: nlcustomers
client_id: nextlayer-sdk-python
username: foobar
password: topsecret
extra_params:
audience: nextlayer-sdk-python
Except for username, all settings are optional, but if no password is
supplied in config, the password will be asked interactively (if STDIN is a TTY) !
Alternatively the username can be suppled in the NEXTLAYERSDK_USERNAME environment
variable or directly passed to the NlAuth constructor.
Alternatively the password can be suppliend in the NEXTLAYERSDK_PASSWORD environment
variable.
Usage
import requests
from nextlayer.sdk.auth import NlAuth
nlauth = NlAuth()
access_token = nlauth.get_access_token()
# make Request to some API Endpoint
rsp = requests.get(
"https://portal.nextlayer.at/apis/v1/users/self",
headers={"Authorization": "Bearer " + access_token},
)
print(rsp.json())
You need to call the .get_access_token() Method every time you make API-Calls,
because it checks if the Token is still valid and will refresh it if necessary.
Usage with httpx
import httpx
from nextlayer.sdk.auth_httpx import NlHttpxAuth
client = httpx.Client(
timeout=httpx.Timeout(30.0),
base_url=f"https://portal.nextlayer.at/apis/v1",
auth=NlHttpxAuth(),
)
print(client.get("/users/self").json())
Usage fron commandline
The package also installs a commandline utility nextlayer-auth which takes care
of obtaining an access token and printing out a proper Authorization: header.
curl -H "`nextlayer-auth`" https://portal.nextlayer.at/apis/v1/users/self
It can also be used to "logout" by cleaning up tokens in the yaml file with:
nextlayer-auth clear
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nextlayer_sdk_python-1.1.0.tar.gz.
File metadata
- Download URL: nextlayer_sdk_python-1.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.11 Linux/6.1.0-41-cloud-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09d25e69b4af440d79f0aab520c2b436effbd72f1de6a82379eba050c4fa0575
|
|
| MD5 |
d048bf4534483c2a9c1c94e82bcf68d5
|
|
| BLAKE2b-256 |
decce5dc56caf3cc99241ba7e1e389f371b8af907655da5fbd2c94e45afaf2fc
|
File details
Details for the file nextlayer_sdk_python-1.1.0-py3-none-any.whl.
File metadata
- Download URL: nextlayer_sdk_python-1.1.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.11 Linux/6.1.0-41-cloud-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d42405e67b5d881c833907619ca91dc15b037242b6994073515a76047c37eeef
|
|
| MD5 |
b132306a05ecd6218b5d6ad154a05768
|
|
| BLAKE2b-256 |
49144f3c5bba409cc52c87bf019011356d13a115b562741355b26b984e9bdc57
|