API Module

The API module provides a comprehensive client for interacting with the Annex Brands ABC API.

class ABConnect.api.ABConnectAPI(*args, **kwargs)[source]

Bases: object

API client for ABConnect

example usage: >>> from ABConnect import ABConnectAPI >>> abapi = ABConnectAPI(env=’staging’) >>> companies = abapi.companies.list() >>> print(companies)

__init__(*args, **kwargs)[source]

Initialize the API client.

Parameters:
  • env – Environment name (‘staging’, ‘production’, or None for default)

  • username – Optional username override

  • request – Django request object for session-based auth

property env: str

Current environment type (‘staging’ or ‘production’).

property env_file: str

Current environment file path.

property models

Access to all API models and enums.

Usage:

abapi = ABConnectAPI() m = abapi.models m.ForgotType.USERNAME m.ServiceBaseResponse

class ABConnect.api.RequestHandler(token_storage)[source]

Bases: object

Handles HTTP requests to the ABConnect API.

__init__(token_storage)[source]
call(method, path, *, params=None, files=None, data=None, json=None, headers=None, raw=False, raise_for_status=True)[source]
raise_for_status(response)[source]

Raise an exception if the response status code indicates an error.

upload_file(path, files, *, data=None, params=None, headers=None, raw=False, raise_for_status=True)[source]

Uploads a file to the specified API path using POST.

class ABConnect.api.FileTokenStorage(*args, **kwargs)[source]

Bases: TokenStorage

__init__(*args, **kwargs)[source]
get_token()[source]

Return the current bearer token.

refresh_token()[source]

Refresh the token if needed and return the updated token.

set_token(token)[source]

Store a new token.

class ABConnect.api.SessionTokenStorage(*args, **kwargs)[source]

Bases: TokenStorage

__init__(*args, **kwargs)[source]
get_token()[source]

Return the current bearer token.

refresh_token()[source]

Refresh the token if needed and return the updated token.

set_token(token)[source]

Store a new token.

class ABConnect.api.SwaggerParser(swagger_path=None)[source]

Bases: object

Parser for OpenAPI/Swagger specifications.

__init__(swagger_path=None)[source]

Initialize parser with swagger specification.

Parameters:

swagger_path (Optional[str]) – Path to swagger.json file. If None, uses the bundled swagger.json

get_endpoint_by_operation_id(operation_id)[source]

Find an endpoint by its operation ID.

Return type:

Optional[EndpointDefinition]

get_endpoints()[source]

Get all endpoint definitions as a flat list.

Return type:

List[EndpointDefinition]

get_schemas()[source]

Get all schema definitions.

Return type:

Dict[str, Dict[str, Any]]

parse()[source]

Parse all endpoints and group by resource.

Return type:

Dict[str, List[EndpointDefinition]]

Returns:

Dictionary mapping resource names to their endpoint definitions

parse_by_tags()[source]

Parse all endpoints and group by their tags.

Return type:

Dict[str, List[EndpointDefinition]]

Returns:

Dictionary mapping tag names to their endpoint definitions

resolve_ref(ref)[source]

Resolve a $ref reference.

Parameters:

ref (str) – Reference string like ‘#/components/schemas/CompanyDetails’

Return type:

Dict[str, Any]

Returns:

The resolved object

class ABConnect.api.EndpointDefinition(path, method, operation_id=None, summary=None, description=None, tags=<factory>, parameters=<factory>, request_body=None, responses=<factory>, deprecated=False)[source]

Bases: object

Represents a single API endpoint definition.

__init__(path, method, operation_id=None, summary=None, description=None, tags=<factory>, parameters=<factory>, request_body=None, responses=<factory>, deprecated=False)
deprecated: bool = False
description: Optional[str] = None
get_path_parameters()[source]

Get only path parameters.

Return type:

List[Parameter]

get_query_parameters()[source]

Get only query parameters.

Return type:

List[Parameter]

property method_name: str

Generate a Python method name for this endpoint.

operation_id: Optional[str] = None
request_body: Optional[RequestBody] = None
property resource_name: str

Extract resource name from path or tags.

summary: Optional[str] = None
path: str
method: str
tags: List[str]
parameters: List[Parameter]
responses: Dict[str, Dict[str, Any]]
class ABConnect.api.Parameter(name, location, required=False, schema=<factory>, description=None, default=None)[source]

Bases: object

Represents an API parameter from OpenAPI specification.

__init__(name, location, required=False, schema=<factory>, description=None, default=None)
default: Optional[Any] = None
description: Optional[str] = None
property python_name: str

Convert parameter name to valid Python identifier.

property python_type: str

Get Python type hint from OpenAPI schema.

required: bool = False
name: str
location: str
schema: Dict[str, Any]

Overview

The API module is organized into several components:

  • APIClient - Main client class that provides access to all endpoints

  • Auth - Authentication and token management

  • HTTP - Low-level HTTP request handling

  • Endpoints - Specific endpoint implementations

APIClient

class ABConnect.api.client.ABConnectAPI(*args, **kwargs)[source]

Bases: object

API client for ABConnect

example usage: >>> from ABConnect import ABConnectAPI >>> abapi = ABConnectAPI(env=’staging’) >>> companies = abapi.companies.list() >>> print(companies)

property models

Access to all API models and enums.

Usage:

abapi = ABConnectAPI() m = abapi.models m.ForgotType.USERNAME m.ServiceBaseResponse

property env: str

Current environment type (‘staging’ or ‘production’).

property env_file: str

Current environment file path.

__init__(*args, **kwargs)[source]

Initialize the API client.

Parameters:
  • env – Environment name (‘staging’, ‘production’, or None for default)

  • username – Optional username override

  • request – Django request object for session-based auth

Usage Example

from ABConnect.api import APIClient

# Initialize client
client = APIClient(env='staging')

# Authenticate
client.auth.login(username='user', password='pass')

# Access endpoints
companies = client.companies.get('COMPANY_CODE')
jobs = client.jobs.get('job-id')
user = client.users.me()

Authentication

The API supports multiple authentication methods:

Token-Based Authentication

# Login and get token
client.auth.login(username='user', password='pass')

# Token is automatically stored and used for requests
# Logout when done
client.auth.logout()

Session-Based Authentication (Django)

When used in a Django environment, tokens are automatically stored in the session:

# In a Django view
client = APIClient(env='production')
client.auth.login(username=request.POST['username'],
                  password=request.POST['password'])

# Token is stored in request.session

Token Storage

The API client supports flexible token storage:

  • File-based storage - Default for standalone usage

  • Session-based storage - Automatic when Django is detected

  • Custom storage - Implement your own token storage backend

Environment Configuration

# Staging environment
staging_client = APIClient(env='staging')

# Production environment
prod_client = APIClient(env='production')

# Custom base URL
custom_client = APIClient(base_url='https://custom.api.com')

Error Handling

All API errors are raised as ABConnectError:

from ABConnect.exceptions import ABConnectError

try:
    result = client.companies.get('INVALID')
except ABConnectError as e:
    print(f"API Error: {e.message}")
    print(f"Status Code: {e.status_code}")
    print(f"Response: {e.response}")

Endpoint Documentation

See the API Reference for detailed documentation of each endpoint.