Skip to main content

Anthropic API client library for kiarina namespace

Project description

kiarina-lib-anthropic

PyPI version Python License: MIT

English | 日本語

[!NOTE] What is this? A package for managing Anthropic API credentials and endpoints with pydantic-settings-manager.

Dependencies

Package Version License
Pydantic Settings >=2.10.1 MIT
pydantic-settings-manager >=3.2.0 MIT

The Anthropic Python SDK is not included as a dependency. Add it to the application that creates the client.

Installation

pip install kiarina-lib-anthropic

Features

  • Configuring an Anthropic Client Store an API key and optional base URL as typed settings.
  • Managing Multiple Configurations Switch between named settings for multiple projects or environments.
  • Loading Environment Variables Load environment variables with the KIARINA_LIB_ANTHROPIC_ prefix.
  • Protecting API Keys Store the API key as SecretStr to prevent exposure in normal string representations.

Configuring an Anthropic Client

Convert AnthropicSettings into arguments for an Anthropic SDK client.

from anthropic import Anthropic

from kiarina.lib.anthropic import AnthropicSettings

settings = AnthropicSettings(api_key="sk-ant-...")
client = Anthropic(
    api_key=(
        settings.api_key.get_secret_value()
        if settings.api_key is not None
        else None
    ),
    base_url=settings.base_url,
)

Both api_key and base_url are optional. When omitted, behavior is determined by the client that receives the settings.

Managing Multiple Configurations

settings_manager uses multiple-settings mode. Place named settings under configs.

kiarina.lib.anthropic:
  default: production
  configs:
    development:
      api_key: sk-ant-development
    production:
      api_key: sk-ant-production
import yaml
from pydantic_settings_manager import load_user_configs

from kiarina.lib.anthropic 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.anthropic import settings_manager

settings_manager.user_config = {
    "default": "development",
    "configs": {
        "development": {"api_key": "sk-ant-development"},
        "production": {"api_key": "sk-ant-production"},
    },
}

Loading Environment Variables

Load a single configuration from environment variables.

export KIARINA_LIB_ANTHROPIC_API_KEY="sk-ant-..."
export KIARINA_LIB_ANTHROPIC_BASE_URL="https://api.anthropic.com"
from kiarina.lib.anthropic import AnthropicSettings

settings = AnthropicSettings()

Protecting API Keys

api_key is a SecretStr. Extract its value explicitly only where required.

api_key = (
    settings.api_key.get_secret_value()
    if settings.api_key is not None
    else None
)

API Reference

kiarina.lib.anthropic

from kiarina.lib.anthropic import (
    AnthropicSettings,
    settings_manager,
)

AnthropicSettings

class AnthropicSettings(BaseSettings):
    def __init__(
        self,
        *,
        api_key: SecretStr | None = None,
        base_url: str | None = None,
    ) -> None: ...

Anthropic client settings.

Fields

  • api_key (SecretStr | None): Anthropic API key.
  • base_url (str | None): Base URL for the Anthropic API.

settings_manager

settings_manager: SettingsManager[AnthropicSettings]

Global instance that manages named Anthropic client settings.

Project details


Download files

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

Source Distribution

kiarina_lib_anthropic-2.3.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

kiarina_lib_anthropic-2.3.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file kiarina_lib_anthropic-2.3.1.tar.gz.

File metadata

  • Download URL: kiarina_lib_anthropic-2.3.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kiarina_lib_anthropic-2.3.1.tar.gz
Algorithm Hash digest
SHA256 8e0fe1de2d4834e1b40cd862c1949fa6ee747016fc13918e5c43a74b1fa6588a
MD5 a7fb778189fe01d7c4c5d168946f04f0
BLAKE2b-256 998e3278ed0656282667e2208802c3b08cee078ffa00ff0174cf498047bafc76

See more details on using hashes here.

Provenance

The following attestation bundles were made for kiarina_lib_anthropic-2.3.1.tar.gz:

Publisher: release-pypi.yml on kiarina/kiarina-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kiarina_lib_anthropic-2.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for kiarina_lib_anthropic-2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 36d31e88441bbfecfebf5e167d941ddca267c51170fcd03937f2bca268c585fc
MD5 a201e998f3965cac36825303bec37bff
BLAKE2b-256 720e62b4a90b16609a7749badb51cab676c86aa3fa47de8c056e39d8eeb8fc92

See more details on using hashes here.

Provenance

The following attestation bundles were made for kiarina_lib_anthropic-2.3.1-py3-none-any.whl:

Publisher: release-pypi.yml on kiarina/kiarina-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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