toml|yaml|json|ini|py
및 사용자 정의 가능한 로더.[default, development, testing, production]
init, list, write, validate, export
와 같은 일반적인 작업을 위한 CLI입니다.$ pip install dynaconf
$ cd path/to/your/project/
$ dynaconf init -f toml
Configuring your Dynaconf environment
------------------------------------------
? The file `config.py` was generated.
?️ settings.toml created to hold your settings.
? .secrets.toml created to hold your secrets.
? the .secrets.* is also included in `.gitignore`
beware to not push your secrets to a public repo.
? Dynaconf is configured! read more on https://dynaconf.com
팁:
dynaconf init -f <fileformat>
toml 에서toml|yaml|json|ini|py
선택할 수 있습니다. toml은 기본값이자 가장 권장되는 구성 형식입니다.
.
├── config.py # This is from where you import your settings object (required)
├── .secrets.toml # This is to hold sensitive data like passwords and tokens (optional)
└── settings.toml # This is to hold your application settings (optional)
config.py
파일에서 Dynaconf init는 다음과 같은 상용구를 생성합니다.
from dynaconf import Dynaconf
settings = Dynaconf (
envvar_prefix = "DYNACONF" , # export envvars with `export DYNACONF_FOO=bar`.
settings_files = [ 'settings.yaml' , '.secrets.yaml' ], # Load files in the given order.
)
팁: 위에 표시된 대로
init
명령을 사용하는 대신 파일을 직접 생성할 수 있으며 기본config.py
대신 원하는 이름을 지정할 수 있습니다(파일은 가져올 수 있는 Python 경로에 있어야 함). - 사용할 수 있는 추가 옵션 보기 https://dynaconf.com의Dynaconf
클래스 초기화 프로그램에 전달
settings.{toml|yaml|ini|json|py}
username = " admin "
port = 5555
database = { name = ' mydb ' , schema = ' main ' }
.secrets.{toml|yaml|ini|json|py}
password = " secret123 "
중요:
dynaconf init
명령은 공개 저장소에 노출되는 것을 방지하기 위해.gitignore
에.secrets.*
를 넣습니다. 그러나 이를 로컬 환경에서 안전하게 유지하는 것은 귀하의 책임입니다. 또한 프로덕션 환경에 대한 권장 사항은 내장된 저장소를 사용하는 것입니다. 비밀번호 및 토큰에 대한 Hashicorp Vault 서비스를 지원합니다.
선택적으로 이제 환경 변수를 사용하여 실행별 또는 환경별 값을 재정의할 수 있습니다.
# override `port` from settings.toml file and automatically casts as `int` value.
export DYNACONF_PORT=9900
코드에서 settings
개체를 가져옵니다.
from path . to . project . config import settings
# Reading the settings
settings . username == "admin" # dot notation with multi nesting support
settings . PORT == 9900 # case insensitive
settings [ 'password' ] == "secret123" # dict like access
settings . get ( "nonexisting" , "default value" ) # Default values just like a dict
settings . databases . name == "mydb" # Nested key traversing
settings [ 'databases.schema' ] == "main" # Nested key traversing
할 수 있는 일이 더 많습니다. 문서를 읽어보세요: http://dynaconf.com
주요 토론은 토론 탭에서 진행됩니다. CONTRIBUTING.md 가이드에 참여하는 방법에 대해 자세히 알아보세요.
Rust 프로젝트에서 사용할 Dynaconf와 유사한 것을 찾고 있다면: https://github.com/rubik/hydroconf
그리고 로고를 주신 Caneco에게 특별히 감사드립니다.