API Documentation
- API Keys Overview & Getting Started
- Creating & Managing API Keys
- Authentication & Scopes
- Read-Only Endpoints Reference
- Error Handling & Troubleshooting
- Best Practices & Security
- Python Integration Examples
- JavaScript Integration Examples
- Bulk Import API, AIRTA & Imported Reports
- AILP - LLM compliance SDK (@airtasystems/ailp)
Python Integration Examples
Jan 15, 2025
Overview
Simple Python examples for working with the AIRTA Systems API using API keys.
Setup Instructions
1. Create a Virtual Environment
# Create a new virtual environment
python3 -m venv venv
# Activate the virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
2. Install Dependencies
pip install requests
3. Create Your Script
Create a new Python file (e.g., api_example.py) and copy one of the examples below.
4. Run Your Script
python api_example.py
Basic Example
import os
import requests
import json
# Get API key and base URL from environment variables, with defaults
API_BASE = os.getenv('API_BASE', 'https://airtasystems.com')
API_KEY = os.getenv('API_KEY', 'gb_live_your_api_key_here')
headers = {'Authorization': f'Bearer {API_KEY}'}
# Get submissions
response = requests.get(f'{API_BASE}/api/v2/submissions', headers=headers)
data = response.json()
# Print the full JSON response
print(json.dumps(data, indent=2))
You can set environment variables before running:
# On macOS/Linux:
export API_BASE="http://localhost:3000"
export API_KEY="gb_live_your_api_key_here"
python api_example.py
# On Windows:
set API_BASE=http://localhost:3000
set API_KEY=gb_live_your_api_key_here
python api_example.py
All Endpoints
Get Programs
import os
import requests
import json
API_BASE = os.getenv('API_BASE', 'https://airtasystems.com')
API_KEY = os.getenv('API_KEY', 'gb_live_your_api_key_here')
headers = {'Authorization': f'Bearer {API_KEY}'}
response = requests.get(f'{API_BASE}/api/v2/programs/company/my-programs', headers=headers)
data = response.json()
print(json.dumps(data, indent=2))
# With filters
params = {'category': 'ai-safety'}
response = requests.get(f'{API_BASE}/api/v2/programs/company/my-programs', headers=headers, params=params)
data = response.json()
print(json.dumps(data, indent=2))
Get Compliance Documents
import os
import requests
import json
API_BASE = os.getenv('API_BASE', 'https://airtasystems.com')
API_KEY = os.getenv('API_KEY', 'gb_live_your_api_key_here')
headers = {'Authorization': f'Bearer {API_KEY}'}
response = requests.get(f'{API_BASE}/api/v2/compliance', headers=headers)
data = response.json()
print(json.dumps(data, indent=2))
# With filters
params = {'programId': '123', 'status': 'approved'}
response = requests.get(f'{API_BASE}/api/v2/compliance', headers=headers, params=params)
data = response.json()
print(json.dumps(data, indent=2))
Get Submissions
import os
import requests
import json
API_BASE = os.getenv('API_BASE', 'https://airtasystems.com')
API_KEY = os.getenv('API_KEY', 'gb_live_your_api_key_here')
headers = {'Authorization': f'Bearer {API_KEY}'}
response = requests.get(f'{API_BASE}/api/v2/submissions', headers=headers)
data = response.json()
print(json.dumps(data, indent=2))
# With filters
params = {'status': 'accepted'}
response = requests.get(f'{API_BASE}/api/v2/submissions', headers=headers, params=params)
data = response.json()
print(json.dumps(data, indent=2))
Get Incident Reports
import os
import requests
import json
API_BASE = os.getenv('API_BASE', 'https://airtasystems.com')
API_KEY = os.getenv('API_KEY', 'gb_live_your_api_key_here')
headers = {'Authorization': f'Bearer {API_KEY}'}
params = {'severity': 'high'}
response = requests.get(f'{API_BASE}/api/v2/incidents/reports', headers=headers, params=params)
data = response.json()
print(json.dumps(data, indent=2))
Get FRIA Assessments
import os
import requests
import json
API_BASE = os.getenv('API_BASE', 'https://airtasystems.com')
API_KEY = os.getenv('API_KEY', 'gb_live_your_api_key_here')
headers = {'Authorization': f'Bearer {API_KEY}'}
params = {'status': 'approved'}
response = requests.get(f'{API_BASE}/api/v2/fria/assessments', headers=headers, params=params)
data = response.json()
print(json.dumps(data, indent=2))
Get Messages
import os
import requests
import json
API_BASE = os.getenv('API_BASE', 'https://airtasystems.com')
API_KEY = os.getenv('API_KEY', 'gb_live_your_api_key_here')
headers = {'Authorization': f'Bearer {API_KEY}'}
params = {'submissionId': '123'}
response = requests.get(f'{API_BASE}/api/v2/messages', headers=headers, params=params)
data = response.json()
print(json.dumps(data, indent=2))
Get Teams
import os
import requests
import json
API_BASE = os.getenv('API_BASE', 'https://airtasystems.com')
API_KEY = os.getenv('API_KEY', 'gb_live_your_api_key_here')
headers = {'Authorization': f'Bearer {API_KEY}'}
response = requests.get(f'{API_BASE}/api/v2/teams', headers=headers)
data = response.json()
print(json.dumps(data, indent=2))
All-in-One Script (Auto-Setup)
This complete script automatically sets up the virtual environment, installs dependencies, and runs all endpoints. Just save it and run - no manual setup needed!
import os
import sys
import subprocess
import json
# ==========================================
# PART 1: AUTO-SETUP (Bootstrapper)
# ==========================================
# This section checks if the venv exists and is active.
# If not, it creates it, installs 'requests', and restarts the script.
VENV_DIR = "venv"
def is_venv():
"""Check if running inside a virtual environment."""
return (hasattr(sys, 'real_prefix') or
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
if not is_venv():
print("--- Setting up environment ---")
# 1. Create venv if missing
if not os.path.exists(VENV_DIR):
print(f"Creating virtual environment '{VENV_DIR}'...")
subprocess.check_call([sys.executable, "-m", "venv", VENV_DIR])
# 2. Define paths based on OS
if os.name == 'nt': # Windows
venv_python = os.path.join(VENV_DIR, "Scripts", "python.exe")
venv_pip = os.path.join(VENV_DIR, "Scripts", "pip.exe")
else: # Mac/Linux
venv_python = os.path.join(VENV_DIR, "bin", "python")
venv_pip = os.path.join(VENV_DIR, "bin", "pip")
# 3. Install dependencies
print("Installing 'requests'...")
subprocess.check_call([venv_pip, "install", "requests", "--quiet"])
# 4. Rerun this script using the venv python
print("--- Setup complete. Running Logic --- \n")
subprocess.check_call([venv_python] + sys.argv)
sys.exit()
# ==========================================
# PART 2: API LOGIC
# ==========================================
# This code only runs once the setup above is complete.
import requests
API_BASE = os.getenv('API_BASE', 'https://airtasystems.com')
API_KEY = os.getenv('API_KEY', 'gb_live_your_api_key_here')
HEADERS = {'Authorization': f'Bearer {API_KEY}'}
def get_data(title, endpoint):
"""Simple fetcher without params/filters"""
print(f"Fetching: {title}")
try:
response = requests.get(f"{API_BASE}/api/v2/{endpoint}", headers=HEADERS)
if response.status_code == 200:
print(json.dumps(response.json(), indent=2))
else:
print(f"Error {response.status_code}: {response.text}")
except Exception as e:
print(f"Connection failed: {e}")
print("-" * 40)
if __name__ == "__main__":
# 1. Programs
get_data("Programs", "programs/company/my-programs")
# 2. Compliance
get_data("Compliance Documents", "compliance")
# 3. Submissions
get_data("Submissions", "submissions")
# 4. Incident Reports
get_data("Incident Reports", "incidents/reports")
# 5. FRIA Assessments
get_data("FRIA Assessments", "fria/assessments")
# 6. Messages
get_data("Messages", "messages")
# 7. Teams
get_data("Teams", "teams")
Usage: Save this script as api_all_in_one.py and simply run:
python api_all_in_one.py
The script will automatically:
- Create a virtual environment if it doesn't exist
- Install the
requestslibrary - Run all API endpoints and print the JSON responses
Set environment variables before running (optional):
# On macOS/Linux:
export API_BASE="http://localhost:3000"
export API_KEY="gb_live_your_api_key_here"
python api_all_in_one.py
# On Windows:
set API_BASE=http://localhost:3000
set API_KEY=gb_live_your_api_key_here
python api_all_in_one.py