Skip to content

Latest commit

 

History

History
61 lines (42 loc) · 1.86 KB

File metadata and controls

61 lines (42 loc) · 1.86 KB

Python example for the Qonic API

A python example for accessing the Qonic API

Setup

Follow these steps to configure and run the Python example for the Qonic API.

1. Prerequisites

You’ll need:

2. Copy the environment template

cp .env.example .env

3. Configure .env

# From your Developer Portal application
QONIC_CLIENT_ID=YOUR_CLIENT_ID
QONIC_CLIENT_SECRET=YOUR_CLIENT_SECRET

# Must exactly match a whitelisted redirect URI
QONIC_REDIRECT_URI=http://localhost:8765/callback

# Optional: local callback server port (should match the redirect URI)
QONIC_LOCAL_PORT=8765

# Space-separated scopes required for the sample
QONIC_SCOPES=projects:read models:read

Notes

  • QONIC_REDIRECT_URI must match a whitelisted Redirect URI exactly (scheme, host, port, path).
  • The sample spins up a tiny local HTTP server on QONIC_LOCAL_PORT to receive the authorization code.
  • PKCE is supported out of the box; no extra setup is required.

4. Install dependencies

pip install -r requirements.txt

5. Run the example

python sample.py

Your default browser will open, prompting you to log in and authorize the application. After authorization, the script will receive an access token that can be used to make requests against the api.

Project structure

The main example is in sample.py. This file includes all the configuration for authentication and example requests.

All authentication-related code is in oauth.py. This file uses the OAuth authorization code flow to obtain an access token. A local web server is started to receive the authorization code and token response from the authentication server.