Skip to main content

applica-iam-client

Python client for the Applica IAM service. Async-only, type-safe, mirroring the TypeScript @applica-software-guru/iam-client.

Info Details
Version 0.1.*
Author Roberto Conte Rosito (Applica)
Repository https://bitbucket.org/applicaguru/iam-client-py
License MIT

Installation

pip install applica-iam-client

Quick Start

import asyncio

from iam_client import create_iam_client


async def main():
    async with create_iam_client(api_url="https://server.com/api", api_key="your-system-api-key") as iam:
        await iam.auth.login({"username": "user@test.com", "password": "secret"})
        tenants = await iam.tenants.search({"keyword": "test"})
        user = await iam.users.get_by_id("user-id")
        await iam.roles.register({"code": "EDITOR", "name": "Editor", "permissions": ["read", "write"]})


asyncio.run(main())

Authentication

The IAM backend uses three security chains with different authentication requirements:

Endpoints Auth required Notes
/auth/** None Public endpoints (login, register, activate, recover)
/tenants/** System API key only Requires x-api-key header matching the server's iam.api-key. Bearer tokens are not accepted.
/users/**, /roles/**, /projects/**, /devices/** Bearer token or API key Any of these methods works: JWT from login, system API key, or tenant API key

How authentication works in the client

When you set api_key on the client, the x-api-key header is sent on every request. When a user is logged in, the Authorization: Bearer <token> header is also sent. The API key takes priority if both are present.

Scenario 1 — Server-side / admin scripts (no user login):

Use the system API key. This grants ROLE_SYSTEM and gives access to all endpoints including /tenants/**:

iam = create_iam_client(api_url="https://server.com/api", api_key="your-system-api-key")

# No login needed — the API key authenticates all requests
await iam.tenants.register({"code": "new-tenant", "name": "New Tenant"})
await iam.users.search({})
await iam.roles.register({"code": "EDITOR", "name": "Editor"})

Scenario 2 — Application with logged-in user:

After login, the Bearer token authenticates requests to /users/**, /roles/**, /projects/**, /devices/**. No API key needed for these endpoints:

iam = create_iam_client(api_url="https://server.com/api")

await iam.auth.login({"username": "admin@test.com", "password": "secret"})

# These work with the Bearer token from login
await iam.users.search({})
await iam.roles.register({"code": "EDITOR", "name": "Editor"})
await iam.projects.search({})

# This will FAIL — /tenants/** requires the system API key, not a Bearer token
await iam.tenants.search({})  # 403

Scenario 3 — Application that also needs tenant management:

Provide both. The API key handles /tenants/**, the Bearer token handles everything else (or the API key handles everything):

iam = create_iam_client(api_url="https://server.com/api", api_key="your-system-api-key")

await iam.auth.login({"username": "admin@test.com", "password": "secret"})

# All endpoints work
await iam.tenants.search({})
await iam.users.search({})

What is the system API key and where to find it

The system API key is configured server-side in the IAM backend's application.yaml:

iam:
  api-key: "your-secret-key-here"

This is the master key that grants ROLE_SYSTEM access. It is set by the server administrator and should be treated as a secret. The GodAuthenticationFilter on the backend reads the x-api-key header from incoming requests and compares it against this configured value.

There is no API endpoint to generate or rotate this key — it is a static configuration value managed at deployment time. To change it, update the iam.api-key property in the server configuration and restart the IAM service.

Important: The system API key gives unrestricted access to all endpoints. Never expose it in client-side code in production. It is intended for server-to-server communication, admin scripts, and development environments.

Architecture

IamClient
  ├── auth: AuthService          → /auth/*
  ├── users: UserService         → /users/*
  ├── tenants: TenantService     → /tenants/*
  ├── projects: ProjectService   → /projects/*
  ├── roles: RoleService         → /roles/*
  └── devices: DeviceService     → /devices/*

Documentation

Topic Description
Getting Started Installation, configuration, async usage
Architecture IamClient structure, HttpClient, project layout
AuthService Authentication, session, impersonation, PIN login
UserService User CRUD, roles, tenant/project assignment
TenantService Tenant CRUD (requires system API key)
ProjectService Project CRUD within tenants
RoleService Role and permission management
DeviceService Device management for PIN authentication
Error Handling & Pagination FailureResponse, error codes, pagination
Storage MemoryStorage, custom IStorage
Type Reference All Pydantic models and DTOs

Scripts

pip install -e ".[dev]"    # Install in dev mode
ruff check src/            # Lint
pytest tests/ -v           # Run tests (requires IAM server)
python -m build            # Build package

License

MIT

Metadata

Release files for applica-iam-client 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for applica-iam-client 0.1.1
File Size Uploaded
applica_iam_client-0.1.1.tar.gz 25.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for applica-iam-client 0.1.1
File Interpreter ABI Platform
applica_iam_client-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 47.4 kB

Release files / applica_iam_client-0.1.1.tar.gz

Download URL applica_iam_client-0.1.1.tar.gz
Size 25.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9a7f3dd1a4a5fbbc795d360addfde75bbb6999276a39141bebc6e37908770a5b
BLAKE2b-256 checksum
How to use checksums
c1ff36cb7b37cdbbd279742c6baca98b116cea9685d01aed4e3bd478cb0859d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / applica_iam_client-0.1.1-py3-none-any.whl

Download URL applica_iam_client-0.1.1-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13b415ebafd5a417e767f058ea6f99414c7f6f24536104d0fab64cd189e71df7
BLAKE2b-256 checksum
How to use checksums
f9ccec3e94a822775785246e9f7d7c3faf33c1e24d9cf8a464e30559182f929d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page