Skip to main content

Lightweight Spring Cloud Config client for Python

Project description

Spring Config Client for Python

A lightweight Python client for Spring Cloud Config Server. Load your centralized configuration into Python applications at startup.

Why This Exists

Spring Cloud Config Server is great for centralized configuration management, but Python clients were either outdated or overcomplicated. This library does one thing well: fetch configuration from your Spring Config Server and load it into your application's environment.

Installation

pip install spring-config-client-python

Quick Start

from spring_config_client import SpringConfigClient
import os

# Initialize and load config at application startup
client = SpringConfigClient(
    server_url="https://config.example.com",
    app_name="my-python-service",
    profile="production",
    username="config-admin",  # optional, for basic auth
    password="secret"          # optional
)

# Fetch and load all configuration into os.environ
config = client.fetch_and_load()

# Access your configuration
db_host = os.environ.get('DB_HOST')
api_key = os.environ.get('API_KEY')

How It Works

  1. Fetches configuration from Spring Config Server using the standard API endpoint: /{application}/{profile}
  2. Merges multiple property sources with correct precedence (profile-specific overrides defaults)
  3. Interpolates property placeholders like ${DB_HOST} from existing environment variables
  4. Loads everything into os.environ as-is (including dotted keys like spring.datasource.url)

Configuration Keys

Your Spring Config Server can return keys in any format:

  • Environment variable style: DATABASE_URL, API_KEY
  • Spring property style: spring.datasource.url, logging.level.root
  • Mixed: Whatever you configure in your .properties or .yml files

All keys are loaded as-is into os.environ. No transformation, no magic.

Property Interpolation

The client supports Spring-style property placeholders:

# In your Spring Config Server
DATABASE_URL=postgresql://${DB_HOST}:${DB_PORT}/mydb

The client will resolve ${DB_HOST} and ${DB_PORT} from your existing environment variables.

Features

  • ✅ Loads configuration at startup (no runtime refresh)
  • ✅ Basic authentication support
  • ✅ Property placeholder interpolation (${VAR})
  • ✅ Correct property source precedence
  • ✅ Zero dependencies except requests
  • ✅ Works with Spring Cloud Config Server 2025.0.0

What This Library Does NOT Do

  • ❌ Runtime configuration refresh - load once at startup only
  • ❌ Encryption/decryption - use Spring Config Server's encryption features
  • ❌ Advanced retry logic - fails fast if server is unreachable
  • ❌ Configuration validation - that's your application's responsibility

This is intentional. Keep it simple.

Example with Docker

FROM python:3.11-slim

ENV CONFIG_SERVER_URL=https://config.example.com
ENV CONFIG_APP_NAME=my-service
ENV CONFIG_PROFILE=production

COPY . /app
WORKDIR /app

RUN pip install spring-config-client-python

CMD python app.py
# app.py
import os
from spring_config_client import SpringConfigClient

# Load config from environment
client = SpringConfigClient(
    server_url=os.environ['CONFIG_SERVER_URL'],
    app_name=os.environ['CONFIG_APP_NAME'],
    profile=os.environ['CONFIG_PROFILE']
)

client.fetch_and_load()

# Your application code here

Error Handling

The client fails fast if the config server is unreachable. This is by design - your service shouldn't start without proper configuration.

try:
    client.fetch_and_load()
except requests.RequestException as e:
    print(f"Failed to load configuration: {e}")
    sys.exit(1)

Requirements

  • Python 3.9+
  • Spring Cloud Config Server 2025.0.0 (or compatible versions)

License

MIT

Contributing

Found a bug? Have a feature request? Open an issue on GitHub.

Keep it simple. This library does one thing well and that's enough.

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

spring_config_client_python-0.1.3.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

spring_config_client_python-0.1.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file spring_config_client_python-0.1.3.tar.gz.

File metadata

File hashes

Hashes for spring_config_client_python-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e1f01d5dda8ab8acf91143760caf1453d84439d455a174aa65cc75814f9519a2
MD5 90f41c656263ed640469bef14db2de37
BLAKE2b-256 8551fb85d84e68fa337670b90d3e44934f2bd8e378834f1ef21da3f2417d2359

See more details on using hashes here.

Provenance

The following attestation bundles were made for spring_config_client_python-0.1.3.tar.gz:

Publisher: python-publish.yml on tcivie/spring-config-client-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 spring_config_client_python-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for spring_config_client_python-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 39100c41a9da675e15c6dd19bb2caaf4bcaa05a05e511d60296570e7a206387f
MD5 dfb4f7f7ca2b3b1829bca869153cfae3
BLAKE2b-256 3f597a3bc861da954d08a41655d8c32819a404b827d7145506c8e91de2417fe7

See more details on using hashes here.

Provenance

The following attestation bundles were made for spring_config_client_python-0.1.3-py3-none-any.whl:

Publisher: python-publish.yml on tcivie/spring-config-client-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