Imbi API Client¶
The imbi_common.api subpackage provides an async HTTP client for
talking to the Imbi API and a pydantic_settings.BaseSettings class
for configuring it from environment variables.
It is used by services that integrate with Imbi (e.g. imbi-gateway)
to record releases, push deployment events, patch project metadata,
and look up users by external identity.
Overview¶
imbi_common.api.client.Imbi is a thin subclass of
httpx.AsyncClient that:
- Sets the
AuthorizationandUser-Agentheaders on every request. - Adds task-oriented helpers for the bookkeeping endpoints
(
patch_project,find_user_by_identity,create_release,record_deployment). - Logs non-2xx responses at warning level while still returning the raw response so callers can decide how to react.
imbi_common.api.settings.Settings loads configuration from
environment variables prefixed with IMBI_CLIENT_. The expected
variables are:
| Field | Environment variable | Default |
|---|---|---|
api_base_url |
IMBI_CLIENT_API_BASE_URL |
http://imbi-api:8000 |
api_token |
IMBI_CLIENT_API_TOKEN |
required |
user_agent |
IMBI_CLIENT_USER_AGENT |
None (use the default imbi-common/{version}) |
Basic Usage¶
from imbi_common.api import Imbi, Settings
settings = Settings()
async with Imbi(
base_url=str(settings.api_base_url),
token=settings.api_token.get_secret_value(),
user_agent=settings.user_agent,
) as client:
response = await client.create_release(
'my-org',
'my-project',
{'version': '1.2.3', 'title': 'v1.2.3'},
)
response.raise_for_status()
The constructor parameters mirror what most services want to override
explicitly — base URL, bearer token, optional user-agent, optional
timeout. Settings is provided for the common case of pulling those
values from the environment, but callers are free to build an Imbi
client from any other source.
Status-Code Conventions¶
Two endpoints have idempotency conventions baked into the helpers:
create_releasetreats409 Conflictas success — the release already exists — and does not log a warning. Other non-2xx responses are logged.record_deploymenttreats404 Not Foundas a non-fatal "release missing" condition and does not log a warning. Other non-2xx responses are logged.
In both cases the raw httpx.Response is returned so the caller can
distinguish these states from a fully successful 2xx.
API Reference¶
Client¶
Imbi ¶
Bases: AsyncClient
Async HTTP client for the Imbi API.
Wraps httpx.AsyncClient with the Authorization and
User-Agent headers wired up and adds high-level methods for the
bookkeeping endpoints that integrating services call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Root URL of the Imbi API (e.g. |
required |
token
|
str
|
Bearer token sent on every request. |
required |
user_agent
|
str | None
|
Optional |
None
|
timeout
|
float | None
|
Optional request timeout in seconds. When omitted,
|
None
|
Source code in src/imbi_common/api/client.py
create_release
async
¶
POST a new release to the project's releases collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
org_slug
|
str
|
Organization slug. |
required |
project_id
|
str
|
Project identifier. |
required |
body
|
Mapping[str, object]
|
Release payload ( |
required |
Returns:
| Type | Description |
|---|---|
Response
|
The raw |
Response
|
an idempotent success and is not logged; other non-2xx |
Response
|
responses are logged at warning level. |
Source code in src/imbi_common/api/client.py
find_user_by_identity
async
¶
Look up an Imbi user by external identity subject.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin_slug
|
str
|
Slug of the identity plugin (e.g. |
required |
subject
|
str
|
The plugin-specific subject identifier. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The user's email — the principal identity used by the |
str | None
|
Release |
str | None
|
identity connection matches or the lookup fails. Transport |
str | None
|
errors and malformed JSON responses are also coerced to |
str | None
|
|
Source code in src/imbi_common/api/client.py
patch_project
async
¶
patch_project(
org_slug: str,
project_id: str,
patch: Iterable[Mapping[str, object]],
) -> httpx.Response
Send a JSON Patch to a project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
org_slug
|
str
|
Organization slug. |
required |
project_id
|
str
|
Project identifier. |
required |
patch
|
Iterable[Mapping[str, object]]
|
JSON Patch operations. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
The raw |
Response
|
warning level and returned to the caller. |
Source code in src/imbi_common/api/client.py
record_deployment
async
¶
record_deployment(
org_slug: str,
project_id: str,
version: str,
env_slug: str,
body: Mapping[str, object],
) -> httpx.Response
POST a deployment event onto a release's environment edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
org_slug
|
str
|
Organization slug. |
required |
project_id
|
str
|
Project identifier. |
required |
version
|
str
|
Release version string. |
required |
env_slug
|
str
|
Target environment slug. |
required |
body
|
Mapping[str, object]
|
Deployment event payload ( |
required |
Returns:
| Type | Description |
|---|---|
Response
|
The raw |
Response
|
as a non-fatal "release missing" condition and is not |
Response
|
logged; other non-2xx responses are logged at warning |
Response
|
level. |
Source code in src/imbi_common/api/client.py
Settings¶
Settings ¶
Bases: BaseSettings
Configuration for imbi_common.api.client.Imbi.
Values are loaded from environment variables prefixed with
IMBI_CLIENT_:
IMBI_CLIENT_API_BASE_URL— root URL of the Imbi API. Defaults tohttp://imbi-api:8000.IMBI_CLIENT_API_TOKEN— bearer token sent on every request. Required; instantiation raisesValidationErrorwhen unset.IMBI_CLIENT_USER_AGENT— optionalUser-Agentoverride. When unset, the client falls back toimbi-common/{version}.