Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nextlayer_sdk_python-1.0.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nextlayer_sdk_python-1.0.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file nextlayer_sdk_python-1.0.2.tar.gz.

File metadata

  • Download URL: nextlayer_sdk_python-1.0.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/5.10.0-21-cloud-amd64

File hashes

Hashes for nextlayer_sdk_python-1.0.2.tar.gz
Algorithm Hash digest
SHA256 c5114e6099600399d00c0dfa03a1ba1f11ce4f226671f5c36b9ded8fb160c3d2
MD5 9e67012d3e02522740ca14cfbbbe03bf
BLAKE2b-256 1b65f1ce034955becf200ebe62000a2689527b9d0f0b88b0ffa0d1701f6377bd

See more details on using hashes here.

File details

Details for the file nextlayer_sdk_python-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: nextlayer_sdk_python-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/5.10.0-21-cloud-amd64

File hashes

Hashes for nextlayer_sdk_python-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6cbe163a74a79bc93a956752d2e551eb107b98935f8fe019e587e2364265fbad
MD5 739c48bd5ac33842c531ef499c2039e3
BLAKE2b-256 edcb9172c3983e176d137f400c97f4d59962078a7b053c2025dc434927c4b83c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page