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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

applica_iam_client-0.1.1.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

applica_iam_client-0.1.1-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file applica_iam_client-0.1.1.tar.gz.

File metadata

  • Download URL: applica_iam_client-0.1.1.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for applica_iam_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9a7f3dd1a4a5fbbc795d360addfde75bbb6999276a39141bebc6e37908770a5b
MD5 61284656a15bddf41e03c24db84f4dca
BLAKE2b-256 c1ff36cb7b37cdbbd279742c6baca98b116cea9685d01aed4e3bd478cb0859d5

See more details on using hashes here.

File details

Details for the file applica_iam_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for applica_iam_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 13b415ebafd5a417e767f058ea6f99414c7f6f24536104d0fab64cd189e71df7
MD5 e6eb48d2a5c27ecf9183afcd5ead1f06
BLAKE2b-256 f9ccec3e94a822775785246e9f7d7c3faf33c1e24d9cf8a464e30559182f929d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page