Skip to main content

A lightweight Python SDK for Apollo Config.

Project description

Mini Apollo

A lightweight Python SDK for Apollo Config.

Installation

pip install mini-apollo

Quick Start

from mini_apollo import ApolloClient, ApolloConfig

# Basic client setup
client = ApolloClient(
    server_url="http://your-apollo-server:8080",
    app_id="your-app-id",
    secret="your-secret"
)

# Fetch config once
config = client.fetch_config()
print(config.get("db.host"))

# Auto-refreshing config
config = ApolloConfig(
    client=client,
    auto_refresh=True,
    refresh_interval=30
)
print(config["http.timeout"])

Async Support

import asyncio
from mini_apollo import ApolloClient

async def main():
    client = ApolloClient(
        server_url="http://your-apollo-server:8080",
        app_id="your-app-id"
    )
    
    config = await client.async_fetch_config()
    print(config.get("db.host"))

asyncio.run(main())

Configuration Options

from mini_apollo import ApolloClient, ApolloConfig

client = ApolloClient(
    server_url="http://your-apollo-server:8080",
    app_id="your-app-id"
)

# Specify cluster and namespace
config = client.fetch_config(
    cluster="production",
    namespace="database"
)

# Background refresh
config = ApolloConfig(
    client=client,
    cluster="production",
    namespace="database",
    auto_refresh=True,
    refresh_interval=60
)

Pydantic Integration

from functools import cached_property

from pydantic import Field, computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict

from mini_apollo import ApolloClient, ApolloConfig


class AppSettings(BaseSettings):
    apollo_server_url: str = Field(..., description="Apollo Server URL")
    apollo_app_id: str = Field(..., description="Apollo App ID")
    apollo_cluster: str = Field("default")
    apollo_namespace: str = Field("application")

    model_config = SettingsConfigDict(env_file=".env")

    @computed_field
    @cached_property
    def apollo_client(self) -> ApolloClient:
        return ApolloClient(
            server_url=self.apollo_server_url,
            app_id=self.apollo_app_id
        )

    @computed_field
    @cached_property
    def apollo_config(self) -> ApolloConfig:
        return ApolloConfig(
            client=self.apollo_client,
            cluster=self.apollo_cluster,
            namespace=self.apollo_namespace,
            auto_refresh=True,
            refresh_interval=30
        )

    @computed_field
    @property
    def db_host(self) -> str:
        return self.apollo_config["db.host"]


# Usage
settings = AppSettings()
print(f"Database host: {settings.db_host}")

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

mini_apollo-0.1.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

mini_apollo-0.1.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file mini_apollo-0.1.2.tar.gz.

File metadata

  • Download URL: mini_apollo-0.1.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for mini_apollo-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7813e3f6ca5f431dd6547d4865cc7c38ce5dad8cd2ff59e53f95ac537549b347
MD5 18336ff2076b6b7da2300fca5d01be61
BLAKE2b-256 ec15284c2e5ab294555215ca5eeda42c3992ae385018ca237cb1a07d751a1f07

See more details on using hashes here.

File details

Details for the file mini_apollo-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mini_apollo-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for mini_apollo-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 491093e7fda32754ff204430c045e7af6cd7fd8036ce0c222efaebbcd88138c9
MD5 589064695d6c1b3df5e013fc60bddb58
BLAKE2b-256 90ec4c21dcbda72b15fc5fa51ca57d27f5b4ed923d0c35286eed8633c20738a0

See more details on using hashes here.

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