Skip to main content

A Python library to fetch configuration properties from the Spring Cloud Config Server

Project description

spring-cloud-config-client

A helper library written in Python to fetch configuration properties from the Spring Cloud Config server.

Development Setup

To contribute to this project, you’ll need to install some common prerequisites first, and then follow setup instructions.

Prerequisites

  • uv
  • make for win (required on Windows, usually preinstalled on Linux/macOS)

Setup

# Install Python 3.12 and all dependencies under ./venv locally
make install-dev

How to Use

Fetch configuration the same way you would in a Spring Boot application. Below is a realistic client that pulls database, Kafka, and actuator settings exposed by a Spring Cloud Config Server:

from spring_cloud_config_client import props

# Initialize with your Spring application name and active profiles
props.init("inventory-service", ["prod", "us-east-1"])

# Common Spring properties
db_url = props.get("spring.datasource.url")
db_user = props.get("spring.datasource.username")
db_password = props.get("spring.datasource.password")
connection_timeout = props.get(
    "spring.datasource.hikari.connection-timeout",
    default_value=30_000,
)

# Messaging and observability
kafka_servers = props.get("spring.kafka.bootstrap-servers")
order_topic = props.get("spring.kafka.topic.orders")
actuator_exposed = props.get(
    "management.endpoints.web.exposure.include",
    default_value="health,info,prometheus",
)

# You can also fetch structured sections
logging_levels = props.get("logging.level")
# {'root': 'INFO', 'com.example.inventory': 'DEBUG'}

The library can also make use of environment variables. So if your configuration property contains a placeholder (e.g. ${REDIS_HOST} or ${KAFKA_HOST:localhost} etc.) it will be replaced by its matching environment variable (REDIS_HOST, KAFKA_HOST etc.) if exists.
If the environment variable cannot be found, it searches for an optional default value in the placeholder (e.g. localhost in \${KAFKA_HOST:localhost}) and if this is also not found, it throws an exception. Only alphanumeric characters and dash (-) are supported for default values.

Environment Variables

Configure the client with these environment variables:

  • CONFIG_SERVER_FQDN overrides host and port with a full URL (default http://localhost:8080/)
  • CONFIG_SERVER_HOST host used when CONFIG_SERVER_FQDN is unset (default localhost)
  • CONFIG_SERVER_PORT port paired with CONFIG_SERVER_HOST (default 8080)
  • CONFIG_SERVER_USERNAME HTTP basic auth username (default user)
  • CONFIG_SERVER_PASSWORD HTTP basic auth password (default empty)
  • CONFIG_CLIENT_FAIL_FAST exits when unable to reach the config server if set to True (default False)
  • CONFIG_CLIENT_RETRY_INITIAL_INTERVAL wait (seconds) before the first retry (default 1)
  • CONFIG_CLIENT_RETRY_MAX_INTERVAL maximum wait (seconds) between retries (default 10)
  • CONFIG_CLIENT_RETRY_MAX_ATTEMPTS total attempts before giving up (default 5)
  • CONFIG_CLIENT_RETRY_MULTIPLIER exponential backoff multiplier applied between retries (default 1.1)

Unit Tests

make test

Integration Tests

If you have Docker available, you can run a live integration test suite against an actual Spring Cloud Config Server:

make test-integration

The target spins up the server defined in docker-compose.integration.yml, serves the fixtures from tests/integration/config-repo, runs the tests in tests/integration, and tears everything down when finished.

Versioning

We use semantic versioning. You can check here when and how to bump up the version.

make set-version VERSION=<NEW_VERSION>`

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_cloud_config_client-0.4.0.tar.gz (30.2 kB view details)

Uploaded Source

Built Distribution

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

spring_cloud_config_client-0.4.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file spring_cloud_config_client-0.4.0.tar.gz.

File metadata

File hashes

Hashes for spring_cloud_config_client-0.4.0.tar.gz
Algorithm Hash digest
SHA256 f4c54a64c2cf902a91880ce9c925677df9390b0847f8a2290c7a54556e091bf7
MD5 e4e245f3e484d63dadcde67fddcf3c92
BLAKE2b-256 40a45a8ecce9a45af0631c89e7f2b02be6ecd9bb6fd3115312af19d7200e8694

See more details on using hashes here.

Provenance

The following attestation bundles were made for spring_cloud_config_client-0.4.0.tar.gz:

Publisher: python-package.yml on emrekgn/spring-cloud-config-python-client

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_cloud_config_client-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spring_cloud_config_client-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69917633722289849319758c7a492b6e84f45764f50e446d0a4f15ea17e79931
MD5 1910804a8ffd990cd6800bbe4589fed9
BLAKE2b-256 c80364e4d9e56bafbd145b523e94f7274b10347cfa53e6cfdde29cf42e929197

See more details on using hashes here.

Provenance

The following attestation bundles were made for spring_cloud_config_client-0.4.0-py3-none-any.whl:

Publisher: python-package.yml on emrekgn/spring-cloud-config-python-client

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