Skip to main content

A CLI tool to export environment variables from Python settings files.

Project description

tests lint

sync-settings-dotenv

A Python CLI to sync configs between dotenv files and Python settings module.

It allows to define your application settings in a Python module and use it as a source of truth, instead of maintaining both the settings module and multiple dotenv files manually.

Currently only supports BaseSettings model from pydantic-settings.

Prerequisites

  • uv installed

Installation

The tool can be installed using uv tool:

uv tool install sync-settings-dotenv

After installation, it will be available as sync-settings-dotenv command in your terminal.

Usage

For details on usage, run:

sync-settings-dotenv --help

Generate a .env.example from Python settings file

To generate a .env.example file from a Python settings file, run:

sync-settings-dotenv path.to.settings.Module path/to/.env.example --exact

This command will create a .env.example file with all environment variables defined in the specified settings module, using their default values.

A backup of the previous version will be created as .env.example.backup.timestamp if the file already exists.

Sync from Python settings file to .env file

sync-settings-dotenv path.to.settings.Module /path/to/.env

This command will generate or update the existing .env file with default values from the specified settings module. If the .env file already exists, it will only add missing variables without overwriting existing ones.

To overwrite existing values in the .env file, use the --overwrite-values flag:

sync-settings-dotenv path.to.settings.Module /path/to/.env --overwrite-values

Sync from .env.example file to .env file

It is also possible to sync from an existing .env.example file to a .env file:

sync-settings-dotenv /path/to/.env.example /path/to/.env

It works the same way as syncing from a Python settings file.

Known limitations

This approach only works with BaseSettings models from pydantic-settings.

The tool will execute the module to import the settings class, so any side effects in the module will be triggered.

It is assumed that the settings class can be instantiated without any required parameters other than those provided inside the module itself or via environment variables. Otherwise it will raise an error during execution.

Update and Uninstallation

To upgrade to the latest version, run:

uv tool upgrade sync-settings-dotenv

To uninstall the tool (noooo), run:

uv tool uninstall sync-settings-dotenv

Development

To set up the development environment, run:

make dev-setup

To verify all development checks:

make check-all

To install the tool in editable mode:

make local-install

Take a look at the Makefile for more commands to help with development and testing.

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

sync_settings_dotenv-0.2.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

sync_settings_dotenv-0.2.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file sync_settings_dotenv-0.2.1.tar.gz.

File metadata

  • Download URL: sync_settings_dotenv-0.2.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sync_settings_dotenv-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e1c4e83633b5d8d87fc1060e3c924c82e117933bbecce7cae9b7347c28dc85a1
MD5 a568e756c98dd7161dfad271fe5fedb4
BLAKE2b-256 f6c73260a813188f55e597a3909c8f57180764484e27680e44e4139ccba6abdf

See more details on using hashes here.

File details

Details for the file sync_settings_dotenv-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: sync_settings_dotenv-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sync_settings_dotenv-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53b58941207fbd806e028e336a3898a9bbc62f33883972ce9155c6e46cafbdd1
MD5 1e9d20dac32d60456d9b4a3292d4c153
BLAKE2b-256 98972072ecc06b27dd720eee57ac93ab75e4e1adb9b0160527af9722e4907b9e

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