Skip to main content

Reusable settings loader for Keycloak-secured Envy environments

Project description

nextpertise-envy-loader

A reusable helper for Pydantic that fetches environment variables from an Envy API using a Keycloak-secured token. It automatically writes these variables to a .env.envy file and prepends it to your environment configuration.


📦 Installation

Install via Poetry:

poetry add nextpertise-envy-settings

Or with pip:

pip install nextpertise-envy-settings

🚀 Usage

To load your environment configuration into a .env.envy file:

from nextpertise_envy_settings import EnvySettingsLoader

EnvySettingsLoader.load_env_file(
    envy_env="SCORE_DEVELOPMENT"
)

This will:

  • Check for required settings in environment variables (or fall back to defaults).
  • Load client_id and client_secret from environment or ~/.envy/auth.json if not passed explicitly.
  • Fetch remote settings from the configured Envy environment.
  • Write them to .env.envy in the current directory.

Optional overrides

You can override default URLs or encoding directly:

EnvySettingsLoader.load_env_file(
    envy_env="SCORE_DEVELOPMENT",
    envy_url="https://custom-envy.example.com",
    keycloak_url="https://keycloak.example.com/realms/envy",
    filename=".env.generated",
    encoding="utf-8"
)

✅ If client_id and client_secret are not passed or set in environment variables, they are loaded from ~/.envy/auth.json.

🔧 Environment Variables (optional)

Instead of hardcoding the config, you can also use these environment variables:

Variable Description
ENV_API_BASE_URL Base URL for Envy API
ENV_API_KEYCLOAK_URL Keycloak realm URL
ENV_API_KEYCLOAK_CLIENT_ID OAuth2 client ID
ENV_API_KEYCLOAK_TOKEN OAuth2 client secret
ENV_API_ENVIRONMENT Target environment name

📁 Example .env.envy

MYSQL_USER=abc MYSQL_PASSWORD=xyz REDIS_HOST=localhost

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

nextpertise_envy_settings-0.4.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

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

nextpertise_envy_settings-0.4.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nextpertise_envy_settings-0.4.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.8 Darwin/23.4.0

File hashes

Hashes for nextpertise_envy_settings-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ba67c021193acf9d08153563f96ad4b85db090af856b8d57ae61385e9f0e8460
MD5 14d0264db61c30ded4458042297cb26d
BLAKE2b-256 664587517a8ab0de632bb3cea8de63156027c03b1f81c4ac56b22a7c81ab42ac

See more details on using hashes here.

File details

Details for the file nextpertise_envy_settings-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nextpertise_envy_settings-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 503eb16dd08fe2bdcca51471b6417ca4e0ac764da020833af72448d06f02acc1
MD5 c63fe72e734f095f14d14c0b47fd2508
BLAKE2b-256 94bedf70cbff32a88cc7f218fdf190df5a46d89a4d37e340de2d9beef43274a2

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