common-python-utils
Common Python utilities shared across Kaiano's projects.
Install name: miniapppolis-common-utils (PyPI) · Import namespace: mini_app_polis
The distribution and the import namespace differ on purpose: the published
name is prefixed because the registry is public, while the import namespace
is the one every consumer already writes. Install miniapppolis-common-utils,
import mini_app_polis (for example, from mini_app_polis.google import GoogleAPI).
Installation
Declare a version range in your pyproject.toml and let the lockfile carry
the exact pin:
[project]
dependencies = [
"miniapppolis-common-utils>=8.0,<9",
]
Then uv lock. To move to a newer release, uv lock --upgrade-package miniapppolis-common-utils — no edit to this file.
The base install is small: the API client, run reports, logging, settings and
the other modules every cog uses. The heavy modules each come with an extra;
add the ones your code imports:
| Extra |
Module |
Brings |
google |
mini_app_polis.google |
google-auth, google-api-python-client, gspread |
spotify |
mini_app_polis.spotify |
spotipy |
mp3 |
mini_app_polis.mp3 |
mutagen, music-tag, pyacoustid, musicbrainzngs |
llm |
mini_app_polis.llm |
openai, anthropic, jsonschema |
activity |
mini_app_polis.activity |
sqlalchemy |
testing |
mini_app_polis.testing |
fastapi |
dependencies = [
"miniapppolis-common-utils[google,mp3]>=8.0,<9",
]
Importing a module without its extra fails with ModuleNotFoundError naming
the missing package. Before 8.0 the Google, Spotify and MP3 packages were
installed for every consumer; a cog moving to 8.0 adds the extras for the
modules it imports.
Modules
| Module |
Import |
Description |
activity.py |
from mini_app_polis import activity |
A FastAPI service's Discord feed: committed data changes, faults, announce-on-commit, background faults (activity extra) |
api/ |
from mini_app_polis.api import KaianoApiClient |
HTTP client for internal FastAPI services |
api/contract/ |
from mini_app_polis.api.contract import IngestSet, ENDPOINTS |
Typed request/response models for the Kaiano API endpoints the fleet calls |
asana/ |
from mini_app_polis.asana import AsanaClient |
Asana task creation with external-id idempotency |
config.py |
from mini_app_polis import config |
Env-var driven shared config (Spotify, Google, VDJ) |
deadline.py |
from mini_app_polis.deadline import run_deadline |
A run deadline the library's retry loops respect: no attempt starts, and no backoff is waited out, past it; without_run_deadline() lifts it for cleanup |
discord.py |
from mini_app_polis import discord |
Discord webhook transport: named channels, rate-limit cooldowns, environment labels, never raises |
doppler.py |
from mini_app_polis.doppler import DopplerClient |
Reads and writes secrets in one Doppler config (API or CLI), and the check-doppler-keys console script |
environment.py |
from mini_app_polis.environment import current_environment, effect_enabled |
Which environment this process is in, which outbound effects it may make, and which name an environment-specific variable is read under (_DEV outside production). log_settings(settings, allowlist=None) logs one line per effective setting at startup, with a value only for names on the allowlist (an iterable, or SETTINGS_ALLOWLIST when none is passed; a missing or empty list shows no values) |
google/ |
from mini_app_polis.google import GoogleAPI |
Drive + Sheets facade |
lambda_worker.py |
from mini_app_polis.lambda_worker import deadline, parse_message, process_records |
A Lambda queue consumer's glue: stop before the timeout (RunOutOfTime), read a {type, version, payload} message, name failed records in batchItemFailures |
llm/ |
from mini_app_polis.llm import build_llm, LLMMessage |
OpenAI + Anthropic clients (optional extra) |
logger.py |
from mini_app_polis import logger |
The fleet's logger: level from LOGGING_LEVEL, JSON on Railway, credential-printing libraries held at INFO |
mp3/ |
from mini_app_polis.mp3 import ... |
AcoustID identification, tagging, renaming; mp3.tag.AudioTagger tags MP3, FLAC, Ogg Vorbis, Ogg Opus, M4A, WAV and AIFF |
music/ |
from mini_app_polis.music import normalize_for_matching |
Music data normalization utilities |
pipeline_status.py |
from mini_app_polis.pipeline_status import RunReport, post_findings |
Run reports to the runs channel and graded findings to the API |
request_metrics.py |
from mini_app_polis.request_metrics import RequestMetricsMiddleware |
ASGI middleware publishing an API's request latency and error counts to CloudWatch |
sentry.py |
from mini_app_polis.sentry import init_sentry |
Starts Sentry for a service with the fleet defaults; an empty DSN in production logs an ERROR instead of skipping silently (CD-038) |
spotify/ |
from mini_app_polis.spotify import SpotifyAPI |
Spotipy wrapper; raises SpotifyTokenExpired when Spotify refuses the refresh token (invalid_grant, not retried); every request, token refresh included, is bounded by SPOTIFY_REQUEST_TIMEOUT_SECONDS |
ssm_secrets.py |
from mini_app_polis.ssm_secrets import load_secrets |
Loads a Lambda worker's secrets from SSM Parameter Store into the environment, at cold start and again each invocation |
testing.py |
from mini_app_polis.testing import RouteLedger |
The route ledger (TEST-018): a pytest plugin that fails a whole integration run on any API route no test called, and on exemptions that outlived their reason (testing extra) |
timing.py |
from mini_app_polis import timing |
Per-invocation working vs waiting time, by service, as one CloudWatch line |
vdj/ |
from mini_app_polis.vdj.m3u import ParseFacade |
VirtualDJ M3U parsing |
Usage
KaianoApiClient
from mini_app_polis.api import KaianoApiClient
# Set KAIANO_API_BASE_URL (KAIANO_API_BASE_URL_DEV outside production)
# and this machine's own key (deejay-cog -> DEEJAY_COG_API_KEY) in the
# environment. The machine name is what selects the key variable, and the
# key is what names this caller to the API. Without it the client falls
# back to KAIANO_API_KEY; with neither set, every call raises
# KaianoApiError before any request is sent.
client = KaianoApiClient.from_env("deejay-cog")
result = client.post("/sets", {"name": "My Set"})
A caller with a key of its own, rather than one read from the environment,
passes it as api_key, and names itself in every request with user_agent:
client = KaianoApiClient(api_key=key, user_agent="mini-app-polis-rotate/1")
Filing a task from a working session
file-task puts one task on the board through POST /v1/tasks, as the
claude-session machine, so the task manager stays the one writer to the
board and mints the id. Run it under Doppler in the owner-session project,
which holds CLAUDE_SESSION_API_KEY: