Skip to main content

Quick Start

Basic Authentication

from artos_sdk import ArtosClient

# Initialize with username and password
client = ArtosClient(
    username="your-username",
    password="your-password",
    api_url="https://api.artosai.com"
)

# Client automatically authenticates on first API call
documents = client.documents.list()

Environment Variables

export ARTOS_USERNAME=your-username
export ARTOS_PASSWORD=your-password
export ARTOS_API_URL=https://api.artosai.com
from artos_sdk import ArtosClient

# Uses environment variables automatically
client = ArtosClient()
documents = client.documents.list()

Configuration File

Create artos_config.yaml:
authentication:
  username: "your-username"
  password: "your-password"
  api_url: "https://api.artosai.com"
from artos_sdk import ArtosClient

client = ArtosClient(config_file="artos_config.yaml")
pipelines = client.pipelines.list()

Authentication Methods

Verify Authentication

# Check if authenticated
if client.auth.is_authenticated():
    user_info = client.auth.get_current_user()
    print(f"Logged in as: {user_info['username']}")
    print(f"User level: {user_info['user_level']}")

Manual Authentication

# Force authentication (optional - happens automatically)
client.auth.authenticate()

# Get token information
token_info = client.auth.get_token_info()
print(f"Token expires at: {token_info['expires_at']}")
print(f"Expires in: {token_info['expires_in']} seconds")

Token Refresh

# Force token refresh (usually automatic)
client.auth.refresh_token()

# Check if token is valid
if client.auth.is_token_valid():
    print("Token is valid")

Configuration

Environment Variables

# Required
ARTOS_USERNAME=your-username
ARTOS_PASSWORD=your-password
ARTOS_API_URL=https://api.artosai.com

# Optional
ARTOS_AUTO_REFRESH=true
ARTOS_TOKEN_REFRESH_THRESHOLD=300
ARTOS_MAX_AUTH_RETRIES=3
ARTOS_AUTH_TIMEOUT=30

Configuration File

authentication:
  username: "your-username"
  password: "your-password"
  api_url: "https://api.artosai.com"
  auto_refresh: true
  token_refresh_threshold: 300

Configuration Priority

  1. Direct parameters to ArtosClient()
  2. Environment variables
  3. Configuration file
  4. Default settings

Error Handling

Authentication Errors

from artos_sdk import ArtosClient
from artos_sdk.exceptions import AuthenticationError

try:
    client = ArtosClient(username="user", password="pass")
    client.auth.authenticate()
    
except AuthenticationError as e:
    if e.error_code == "invalid_grant":
        print("Invalid username or password")
    elif e.error_code == "account_locked":
        print("Account temporarily locked")
    elif e.error_code == "rate_limit_exceeded":
        print("Too many login attempts")

Common Error Codes

Error CodeDescriptionSolution
invalid_grantInvalid credentialsCheck username/password
account_lockedAccount lockedWait before retrying
rate_limit_exceededToo many requestsWait before retrying

Validation

Validate Setup

# Validate configuration before use
validation_result = client.auth.validate_config()
if validation_result.is_valid:
    print("Configuration is valid")
else:
    print("Configuration errors:", validation_result.errors)

Health Check

# Test authentication and API connectivity
try:
    client.auth.authenticate()
    health = client.health.check()
    print(f"API status: {health['status']}")
    print("Authentication successful")
except Exception as e:
    print(f"Setup failed: {e}")

Permission Levels

Check User Level

user_info = client.auth.get_current_user()
user_level = user_info['user_level']

if user_level == 'admin':
    # Admin can access system-wide data
    system_analytics = client.analytics.get_system_metrics()
else:
    # Regular users see only their own data
    user_analytics = client.analytics.get_user_metrics()

Security Best Practices

Secure Storage

  • Credentials are stored securely using system keyring
  • Tokens are automatically cleared on logout
  • Use environment variables in production
  • Restrict config file permissions: chmod 600 artos_config.yaml

Production Setup

import os
from artos_sdk import ArtosClient

# Use environment variables in production
client = ArtosClient(
    username=os.getenv('ARTOS_USERNAME'),
    password=os.getenv('ARTOS_PASSWORD'),
    api_url=os.getenv('ARTOS_API_URL')
)

Troubleshooting

Common Issues

Problem: Cannot authenticate
# Check configuration
config = client.auth.get_config()
print(f"API URL: {config.api_url}")
print(f"Username: {config.username}")
Problem: Token expired
# Token refresh is automatic, but you can force it
client.auth.refresh_token()
Problem: Connection issues
# Test API connectivity
health = client.health.check()
print(f"API reachable: {health['status'] == 'healthy'}")

Debug Mode

import logging

# Enable debug logging
logging.basicConfig(level=logging.DEBUG)

# Create client with debug mode
client = ArtosClient(username="user", password="pass", debug=True)

API Reference

Authentication Methods

client.auth.authenticate()           # Manual authentication
client.auth.is_authenticated()       # Check if authenticated
client.auth.get_current_user()       # Get user information
client.auth.refresh_token()          # Force token refresh
client.auth.get_token_info()         # Get token details
client.auth.is_token_valid()         # Check token validity
client.auth.validate_config()        # Validate configuration

Exceptions

from artos_sdk.exceptions import (
    AuthenticationError,     # General auth errors
    TokenRefreshError,       # Token refresh failed
    ConfigurationError,      # Config validation failed
    AccountLockedError,      # Account is locked
    RateLimitError          # Rate limit exceeded
)