Organize your project settings and secrets with ease
Project description
poetry
Easily manage your application settings and secrets
Welcome to Stela
Stela were the "information files" of ancient times. This library aims to simplify your project configurations, proposing an opinionated way to manage your project using dotenv files, or using any source you need.
Install
$ pip install stela
Documentation
Key features:
- Learn once, use everywhere. Stela aims to be easily used in any Python project or Framework.
- Separate settings from secrets from environments. Instead of using a single dotenv file to store all your settings, we use multiple dotenv files, one for each environment. This way, you can split secrets from settings, and you can have different values for the same setting in different environments.
- Easy to implement. Use the command
stela init
to initialize your project and configure.env
and.gitignore
files. - Easy to use. To access you configuration just include
from stela import env
in your code. Simple as that. - One Interface, Any Source. You're not limited to dotenv files. Create your custom logic to import data from any source you need.
Quick Start
Run Stela initialization command. This command will create .env
, .env.local
, .stela
and .gitignore
files.
$ stela init --default
Create the dotenv files and add your settings and secrets.
# Add project settings and fake project secrets to .env
# This file will be commited to your repository
API_URL="http://localhost:8000"
DB_URL="db://fake_user:fake_password@local_db:0000/name"
# my_script.py
from stela import env
API_URL = env.API_URL # http://localhost:8000
DATABASE_URL_CONNECTION = env.DB_URL # db://fake_user:fake_password@local_db:0000/name
# Add real secrets to .env.local
# This file will be ignored by git
DB_URL="db://real_user:real_password@real_db:0000/name"
A single, simple API to access your settings and secrets:
# my_script.py
from stela import env
API_URL = env.API_URL # http://localhost:8000
DATABASE_URL_CONNECTION = env.DB_URL # db://real_user:real_password@real_db:0000/name
Custom Sources
Use a custom, optional, final loader function to load your settings from any source you need.
# .stela
[stela]
final_loader = "path.to.my.final_loader" # Add your final loader to Stela
# Use SSM Parameter Store to load your settings
import boto3
from stela.config import StelaOptions
def final_loader(options: StelaOptions, env_data: dict[str, any]) -> dict[str, any]:
"""Load settings from AWS Parameter Store (SSM) to current Stela data.
Data returned must be a Python Dictionary.
Dict keys will be converted to env properties.
Ex. {'Foo': 'Bar'} will be available as env.Foo
:param env_data: Data parsed from dotenv file (the first loader)
:param options: Stela Options obj
:return dict[str, any]
"""
ssm = boto3.client('ssm')
environment = options.current_environment # The value from STELA_ENV variable. Ex. production
# Get from SSM
response = ssm.get_parameters_by_path(
Path=f'/my-project/settings/{environment}',
WithDecryption=True
)
api_url = response['Parameters']['ApiUrl'] # https://real-api-url.com
env_data.update({'API_URL': api_url})
return env_data
Got your settings and secrets from both dotenv files and SSM Parameter Store:
# my_script.py
from stela import env
API_URL = env.API_URL # https://real-api-url.com
DATABASE_URL_CONNECTION = env.DB_URL # db://real_user:real_password@real_db:0000/name
That's it! Check our Documentation for tons of customization and advice.
Not working?
Don't panic. Get a towel and, please, open an issue.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file stela-8.0.5.tar.gz
.
File metadata
- Download URL: stela-8.0.5.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.1 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44177cbe2a400bceee0da87a9a1da111b5f7ee1dfc2703542126d03d4409051d |
|
MD5 | e3b6832825cf7d0543d676ae023ca9a5 |
|
BLAKE2b-256 | 62a3c6bbf8a040b8323ba4b224033a3691322e37f208e77cc97f8d7017b7e732 |
File details
Details for the file stela-8.0.5-py3-none-any.whl
.
File metadata
- Download URL: stela-8.0.5-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.1 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7983f6dbeedd3340f78406c3c750710d32c0cb8335ac1fc86899c9948d4a4243 |
|
MD5 | fc8819d6e170a0f95a8515a1bcd7062e |
|
BLAKE2b-256 | 3110478d708f48bd717279d3c5bd0104b12f848f40a10480207a7b5670d76e22 |