ini config model for flask
Project description
When ini config file looks like below:
[default]
debug = False
[mysql]
connection = sqlite:///test.db
#connection = mysql+pymysql://root:password@localhost:13306/project?charset=utf8
track_modifications = True
[secure]
secure_key = YjFjMDVkYzAtZGI4YS0xMWU5LWIwMjctMTdhNzg4ZjJiMGUyCg==
[jwt]
secret = YTgzNmM0OWUtNjllMS00MjI4LWFlZTMtNjgxNjAwNDdiNTBlCg==
algorithm = HS256
[test]
int_value = 1231
You need to create class based on ConfigOpts
from flask_fastconfig import ConfigOpts, ConfigGroup
from flask_fastconfig.config_opt import BooleanOpt, StrOpt, IntOpt
import uuid
class CONF(ConfigOpts):
"""
ini configs
"""
class default(ConfigGroup):
debug = BooleanOpt(default=True, app_config="DEBUG")
class mysql(ConfigGroup):
connection = StrOpt(default='sqlite:///gevoton.db', app_config="SQLALCHEMY_DATABASE_URI")
track_modifications = BooleanOpt(default=False, app_config="SQLALCHEMY_TRACK_MODIFICATIONS")
class secure(ConfigGroup):
secure_key = StrOpt(default=uuid.uuid4().hex, app_config="SECRET_KEY")
class jwt(ConfigGroup):
secret = StrOpt(default=uuid.uuid4().hex)
algorithm = StrOpt(default='HS256')
class test(ConfigGroup):
int_value = IntOpt(default=123)
Then you can init flask app like below
from flask import Flask
from test import CONF
app = Flask(__name__)
cfg = CONF(app, "../system/etc/gevoton.ini")
app.config.from_mapping(cfg.get_app_config())
Finally, you can use cfg in other places:
from app import cfg
print(cfg.mysql.connection)
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 flask-fastconfig-0.0.3.tar.gz
.
File metadata
- Download URL: flask-fastconfig-0.0.3.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.5.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97634460d85b1f99728851ed46bf6878ad39eea9a01bd30ff5c166f3e7eac665 |
|
MD5 | 2266d0d201a149ef8bf709382a6ca93f |
|
BLAKE2b-256 | 4a9bc4559da5902747beda47d742388782adcfd3a20eafcb68096936eac373e2 |
File details
Details for the file flask_fastconfig-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: flask_fastconfig-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.5.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e3beb3136421827a6652b180612fd8c8523ac06a7a20be10a21ed25408a1024 |
|
MD5 | 2519482815254bec9a202a39a4cb7869 |
|
BLAKE2b-256 | 3b5d8b2cf40cd7887c9b8cf246f9873458ac58e681f76973f91bfbe43f762a2d |