Skip to content

Set up the Client

Get the latest client for the API from pypi.org: pinexq-client

To authenticate a user to the API, a valid API key is required to derive the user and permissions. It can be obtained from the corresponding portal or from an administrator. The API key is a secret, since it allows full access to your resources, and should be stored securely and not be shared.

To initialize the client the following parts must be supplied:

  • The API host: a URL with port if required
  • The API key (as header)
from httpx import Client
from pinexq.client.job_management.enterjma import enter_jma, create_pinexq_client
from pinexq.client.job_management.hcos.entrypoint_hco import EntryPointHco
# create a configured http client
client = create_pinexq_client("https://myapihost.com", "my api key")
# the client is now ready to be passed to a function entering the API root
entrypoint: EntryPointHco = enter_jma(client)

Note: when using enter_jma() to initially connect to the API, a version check of the client against the API is performed. There will be a warning if your current client is outdated.

Create a separate file (e.g. secret_key.py) that contains your secret (secret = '<api-key>') and import it from there to use it. This file is then excluded from source control (e.g. .gitignore).

from secret import secret_key

This ensures the API key stays on your local machine (when not located in shared folder or checked in).

Set a environment variable to the secret key and access it from here:

  • Powershell: $Env:SECRET_KEY = '<api-key>'
  • CMD: set SECRET_KEY = '<api-key>'
  • Bash: export SECRET_KEY = '<api-key>'

Use the environment variable:

import os
secret_key = os.environ['SECRET_KEY']

The Python package python-dotenv makes managing environmental variables for multiple projects simple; you can set multiple key-value pairs in a .env file, which are loaded as environmental variables (if not already set) with load_dotenv(). This file can be placed in your project directory: if you do, don’t forget to put .env in your .gitignore!

import dotenv
load_dotenv('../.env') # default path is ./.env; $SECRET_KEY loaded if not already set
secret_key = os.environ['SECRET_KEY']

Use keyring to store your secrets

import keyring
secret_key = keyring.get_password('jobmanagement', 'api-key')