All Projects → fscdev → betterconf

fscdev / betterconf

Licence: MIT license
Minimalistic Python library for your configs.

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to betterconf

salak.rs
A multi layered configuration loader and zero-boilerplate configuration parser.
Stars: ✭ 27 (-22.86%)
Mutual labels:  config, env
read-env
🔧 Transform environment variables into JSON object with sanitized values.
Stars: ✭ 60 (+71.43%)
Mutual labels:  config, env
exenv
Exenv makes loading environment variables from external sources easy.
Stars: ✭ 35 (+0%)
Mutual labels:  config, env
goodconf
Transparently load variables from environment or JSON/YAML file.
Stars: ✭ 80 (+128.57%)
Mutual labels:  config, env
env
A lightweight package for loading OS environment variables into structs for Go projects
Stars: ✭ 24 (-31.43%)
Mutual labels:  config, env
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+5200%)
Mutual labels:  config, env
environment
🌳 Environment variable configuration for Node.js made easy.
Stars: ✭ 12 (-65.71%)
Mutual labels:  config, env
ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (+105.71%)
Mutual labels:  config, env
Flex-AntiCheat
Flex AntiCheat - Optimized Configs For Multiple AntiCheats
Stars: ✭ 37 (+5.71%)
Mutual labels:  config
csgo-server-configs
CS:GO Server Configs for Competitive 5v5, Knife Round, Aim Map and FFA Deathmatch
Stars: ✭ 24 (-31.43%)
Mutual labels:  config
crab
Golang API Framework
Stars: ✭ 57 (+62.86%)
Mutual labels:  config
stylelint-config
Sharable stylelint config used by GitHub's CSS
Stars: ✭ 194 (+454.29%)
Mutual labels:  config
envclasses
envclasses is a library to map fields on dataclass object to environment variables.
Stars: ✭ 26 (-25.71%)
Mutual labels:  env
react-native-config-reader
🛠 Easily access any of the build configs defined in build.gradle or info.plist from your JS code.
Stars: ✭ 44 (+25.71%)
Mutual labels:  config
microservice-template
📖 Nest.js based microservice repository template
Stars: ✭ 131 (+274.29%)
Mutual labels:  env
rust cms
使用Rust编写一个CMS(内容管理系统)可以做为个人博客,公司网站
Stars: ✭ 32 (-8.57%)
Mutual labels:  config
dotfiles
Linux configuration files (dotfiles) and some useful scripts
Stars: ✭ 22 (-37.14%)
Mutual labels:  config
config
holy cow, wholly config! Vim, Zshell, Ack, & the rest of my dot-files.
Stars: ✭ 21 (-40%)
Mutual labels:  config
dotfiles
🔧 My dotfiles on  macOS for Neovim, Zsh, kitty, lf, etc
Stars: ✭ 90 (+157.14%)
Mutual labels:  config
configster
Rust library for parsing configuration files
Stars: ✭ 19 (-45.71%)
Mutual labels:  config

Minimalistic Python library for your configs.

Betterconf (better config) is a Python library for project configuration managment. It allows you define your config like a regular Python class.

Features:

  • Easy to hack.
  • Less boilerplate.
  • Minimal code to do big things.

Installation

I recommend you to use poetry:

poetry add betterconf

However, you can use pip:

pip install betterconf

How to?

Try to write a simple config:

from betterconf import field, Config

class MyConfig(Config):
    my_var = field("my_var")

cfg = MyConfig()
print(cfg.my_var)

Try to run:

my_var=1 python our_file.py

With default values:

from betterconf import field, Config

class MyConfig(Config):
    my_var = field("my_var", default="hello world")
    my_second_var = field("my_second_var", default=lambda: "hi") # can be callable!

cfg = MyConfig()
print(cfg.my_var)
print(cfg.my_second_var)
# hello world
# hi

Override values when it's needed (for an example: test cases)

from betterconf import field, Config

class MyConfig(Config):
    my_var = field("my_var", default="hello world")

cfg = MyConfig(my_var="WOW!")
print(cfg.my_var)
# WOW!

By default betterconf gets all values from os.environ but sometimes we need much. You can create own field's value provider in minutes:

from betterconf import field, Config
from betterconf.config import AbstractProvider

class NameProvider(AbstractProvider):
    def get(self, name: str):
        return name

class Cfg(Config):
    my_var = field("my_var", provider=NameProvider())

cfg = Cfg()
print(cfg.my_var)
# my_var

Also we can cast our values to python objects (or just manipulate them):

from betterconf import field, Config
# out of the box we have `to_bool` and `to_int`
from betterconf.caster import to_bool, to_int, AbstractCaster


class DashToDotCaster(AbstractCaster):
    def cast(self, val: str):
        return val.replace("-", ".")

to_dot = DashToDotCaster()

class Cfg(Config):
    integer = field("integer", caster=to_int)
    boolean = field("boolean", caster=to_bool)
    dots = field("dashes", caster=to_dot)

cfg = Cfg()
print(cfg.integer, cfg.boolean, cfg.dots)
# -500, True, hello.world
integer=-500 boolean=true dashes=hello-world python our_file.py

License

This project is licensed under MIT License.

See LICENSE for details.

Made with ❤️ by prostomarkeloff and our contributors.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].