kiarina-llm
A Python library for LLM utilities and context management with type safety and configuration management.
Features
- AppContext Management: Application-level context for platform directories
- RunContext Management: Structured context information for LLM pipeline processing
- Type Safety: Full type hints and Pydantic validation
- Configuration Management: Use
pydantic-settings-managerfor flexible configuration - Filesystem Safe Names: Validated names for cross-platform compatibility
- ID Validation: Structured ID types with pattern validation
Installation
pip install kiarina-llm
Quick Start
Basic Usage
from kiarina.llm.run_context import create_run_context
# Create a run context
context = create_run_context(
tenant_id="tenant-123",
user_id="user-456",
agent_id="my-agent",
time_zone="Asia/Tokyo",
language="ja"
)
print(f"User: {context.user_id}")
print(f"Agent: {context.agent_id}")
Configuration
Configure defaults using pydantic-settings-manager:
from kiarina.llm.run_context import settings_manager
settings_manager.user_config = {
"tenant_id": "default-tenant",
"time_zone": "America/New_York",
"language": "en"
}
Or use environment variables:
export KIARINA_LLM_RUN_CONTEXT_TENANT_ID="prod-tenant"
export KIARINA_LLM_RUN_CONTEXT_TIME_ZONE="Asia/Tokyo"
API Reference
AppContext
Application-level context for platform directories:
from kiarina.llm.app_context import get_app_context, settings_manager
# Configure app context
settings_manager.user_config = {
"app_author": "MyCompany",
"app_name": "MyAIApp"
}
# Get app context
app_context = get_app_context()
print(f"Author: {app_context.app_author}")
print(f"Name: {app_context.app_name}")
RunContext
Run-level context for LLM pipeline processing:
| Field | Type | Description | Example |
|---|---|---|---|
app_author |
FSName |
Application author | "MyCompany" |
app_name |
FSName |
Application name | "MyAIApp" |
tenant_id |
IDStr |
Tenant identifier | "tenant-123" |
user_id |
IDStr |
User identifier | "user-456" |
agent_id |
IDStr |
Agent identifier | "my-agent" |
runner_id |
IDStr |
Runner identifier | "linux" |
time_zone |
str |
IANA time zone | "Asia/Tokyo" |
language |
str |
Language code | "ja" |
currency |
str |
Currency code | "USD" |
metadata |
dict[str, Any] |
Additional metadata | {"version": "1.0"} |
Type Validation
- FSName: Filesystem-safe names (alphanumeric, dots, underscores, hyphens, spaces)
- IDStr: Identifier strings (alphanumeric, dots, underscores, hyphens)
Configuration Reference
AppContext Settings
| Setting | Environment Variable | Default | Description |
|---|---|---|---|
app_author |
KIARINA_LLM_APP_CONTEXT_APP_AUTHOR |
"kiarina" |
Application author |
app_name |
KIARINA_LLM_APP_CONTEXT_APP_NAME |
"kiarina-llm" |
Application name |
RunContext Settings
| Setting | Environment Variable | Default | Description |
|---|---|---|---|
tenant_id |
KIARINA_LLM_RUN_CONTEXT_TENANT_ID |
"" |
Default tenant ID |
user_id |
KIARINA_LLM_RUN_CONTEXT_USER_ID |
"" |
Default user ID |
agent_id |
KIARINA_LLM_RUN_CONTEXT_AGENT_ID |
"" |
Default agent ID |
runner_id |
KIARINA_LLM_RUN_CONTEXT_RUNNER_ID |
platform.system().lower() |
Default runner ID |
time_zone |
KIARINA_LLM_RUN_CONTEXT_TIME_ZONE |
"UTC" |
Default time zone |
language |
KIARINA_LLM_RUN_CONTEXT_LANGUAGE |
"en" |
Default language |
currency |
KIARINA_LLM_RUN_CONTEXT_CURRENCY |
"USD" |
Default currency code |
Development
Prerequisites
- Python 3.12+
Setup
# Clone the repository
git clone https://github.com/kiarina/kiarina-python.git
cd kiarina-python
# Setup development environment (installs tools, syncs dependencies, downloads test data)
mise run setup
Running Tests
# Run format, lint, type checks and tests
mise run package kiarina-llm
# Coverage report
mise run package:test kiarina-llm --coverage
# Run specific tests
uv run --group test pytest packages/kiarina-llm/tests/run_context/
Dependencies
- pydantic - Data validation using Python type hints
- pydantic-settings - Settings management
- pydantic-settings-manager - Advanced settings management
Roadmap
This package is in active development. Planned features include:
- Chat Model Management: Unified interface for different LLM providers
- Agent Framework: Tools for building LLM agents
- Pipeline Management: Workflow management for LLM processing
- Memory Management: Context and conversation memory handling
- Tool Integration: Framework for LLM tool calling
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
This is a personal project, but contributions are welcome! Please feel free to submit issues or pull requests.
Related Projects
- kiarina-python - The main monorepo containing this package
- pydantic-settings-manager - Configuration management library used by this package
Metadata
Release files for kiarina-llm 1.37.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kiarina_llm-1.37.0.tar.gz | 10.0 kB | Without provenance | Details for kiarina_llm-1.37.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kiarina_llm-1.37.0-py3-none-any.whl | Python 3 | none | any | Details for kiarina_llm-1.37.0-py3-none-any.whl |
Total release size: 20.6 kB
Release files / kiarina_llm-1.37.0.tar.gz
| Download URL | kiarina_llm-1.37.0.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
98f672380ddccfdb69f20be8aa094dce332af69d5754ed11031adce0e178ab44
|
|
BLAKE2b-256 checksum How to use checksums |
248364e3a263abadcf3ccf0430651787a57179f0c6f2b1088afa19f105baffeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / kiarina_llm-1.37.0-py3-none-any.whl
| Download URL | kiarina_llm-1.37.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5c42fe4b5382402141ce8e71dfdd10eeca06dc666caca3614901724cbb26f87b
|
|
BLAKE2b-256 checksum How to use checksums |
2e150914153802b58813acda86ce527d45163ff4f7844c2745b936b241c03112
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for kiarina-llm 1.37.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.