A CLI tool to export environment variables from Python settings files.
Project description
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sync_settings_dotenv-0.2.2.tar.gz.
File metadata
- Download URL: sync_settings_dotenv-0.2.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","subcommand":["publish"]},"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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b057f07ee6c193b213d6f37e85312aa8d07cb087d00c32efa2141525ace8ed00
|
|
| MD5 |
ba3a72c4b7f1bc97177b1034aa9fbd55
|
|
| BLAKE2b-256 |
14450def844034cf1053fceeb5f1194da59f1d1f6bd07a7cc583501262040726
|
File details
Details for the file sync_settings_dotenv-0.2.2-py3-none-any.whl.
File metadata
- Download URL: sync_settings_dotenv-0.2.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","subcommand":["publish"]},"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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b20943e8e73325cab7e40969c5dc74381d0a2875265cd9d22d136488836dae5
|
|
| MD5 |
0a23c273e595ef8930d584619dc2e841
|
|
| BLAKE2b-256 |
5921a31adc6b6ac667b1a833536947c7397db00c3fdc9d34096b83323813d38a
|