kiarina-lib-openai
English | 日本語
Dependencies
| Package | Version | License |
|---|---|---|
| Pydantic Settings | >=2.10.1 |
MIT |
| pydantic-settings-manager | >=3.2.0 |
MIT |
The OpenAI Python SDK is not included as a dependency. Add it to the application that creates the client.
Installation
pip install kiarina-lib-openai
Features
- Configuring an OpenAI Client Generate OpenAI SDK client arguments from settings.
- Managing Multiple Configurations Switch between named settings for multiple projects or environments.
- Loading Environment Variables
Load environment variables with the
KIARINA_LIB_OPENAI_prefix. - Using Compatible APIs
Set an OpenAI-compatible API endpoint with
base_url. - Protecting API Keys
Store the API key as
SecretStr.
Configuring an OpenAI Client
to_client_kwargs() converts only configured values to OpenAI SDK argument names.
from openai import OpenAI
from kiarina.lib.openai import OpenAISettings
settings = OpenAISettings(api_key="sk-...")
client = OpenAI(**settings.to_client_kwargs())
organization_id becomes organization. When api_key, organization_id, and base_url are all None, the method returns an empty dict.
Managing Multiple Configurations
settings_manager uses multiple-settings mode. Place named settings under configs.
kiarina.lib.openai:
default: production
configs:
development:
api_key: sk-development
production:
api_key: sk-production
organization_id: org-production
import yaml
from pydantic_settings_manager import load_user_configs
from kiarina.lib.openai import settings_manager
with open("config.yaml", encoding="utf-8") as file:
load_user_configs(yaml.safe_load(file) or {})
settings = settings_manager.get_settings("production")
To configure only this package directly, assign settings_manager.user_config.
from kiarina.lib.openai import settings_manager
settings_manager.user_config = {
"default": "development",
"configs": {
"development": {"api_key": "sk-development"},
"production": {
"api_key": "sk-production",
"organization_id": "org-production",
},
},
}
Loading Environment Variables
Load a single configuration from environment variables.
export KIARINA_LIB_OPENAI_API_KEY="sk-..."
export KIARINA_LIB_OPENAI_ORGANIZATION_ID="org-..."
export KIARINA_LIB_OPENAI_BASE_URL="https://api.openai.com/v1"
from kiarina.lib.openai import OpenAISettings
settings = OpenAISettings()
Using Compatible APIs
from openai import OpenAI
from kiarina.lib.openai import OpenAISettings
settings = OpenAISettings(
api_key="compatible-api-key",
base_url="https://example.com/v1",
)
client = OpenAI(**settings.to_client_kwargs())
Protecting API Keys
to_client_kwargs() returns the secret value of api_key so it can be passed to the OpenAI SDK. Do not log the returned dictionary.
API Reference
kiarina.lib.openai
from kiarina.lib.openai import (
OpenAISettings,
settings_manager,
)
OpenAISettings
class OpenAISettings(BaseSettings):
def __init__(
self,
*,
api_key: SecretStr | None = None,
organization_id: str | None = None,
base_url: str | None = None,
) -> None: ...
def to_client_kwargs(self) -> dict[str, Any]: ...
OpenAI client settings.
Fields
api_key(SecretStr | None): OpenAI API key.organization_id(str | None): OpenAI organization ID.base_url(str | None): Base URL for the OpenAI API.
to_client_kwargs
Converts fields whose values are not None into OpenAI SDK client arguments.
Returns
dict[str, Any]: A dictionary containing configured values amongapi_key,organization, andbase_url.
settings_manager
settings_manager: SettingsManager[OpenAISettings]
Global instance that manages named OpenAI client settings.
Metadata
Release files for kiarina-lib-openai 2.3.1
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_lib_openai-2.3.1.tar.gz | 5.9 kB | With provenance | Details for kiarina_lib_openai-2.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kiarina_lib_openai-2.3.1-py3-none-any.whl | Python 3 | none | any | Details for kiarina_lib_openai-2.3.1-py3-none-any.whl |
Total release size: 10.2 kB
Release files / kiarina_lib_openai-2.3.1.tar.gz
| Download URL | kiarina_lib_openai-2.3.1.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bcacae8867114c3aecde3e789934ec26812a79f259690064dfc099cbcf208ab2
|
|
BLAKE2b-256 checksum How to use checksums |
289d3e848543b17f1bbe3606cfbd84616ad57776085507418e714ec5833da878
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logRelease files / kiarina_lib_openai-2.3.1-py3-none-any.whl
| Download URL | kiarina_lib_openai-2.3.1-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2cbf97262b865defc483ea1eb0891f8c71fe84fe4587a9c6023d57a8146f0fb0
|
|
BLAKE2b-256 checksum How to use checksums |
6b30118e076fb9bcb39aa997c62c5afede642b7468ed17777ded63428d2b0a74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logSecurity for kiarina-lib-openai 2.3.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for kiarina_lib_openai-2.3.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 2, 2026.
Transparency logA 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.