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
flask-fastconfig-0.0.3.tar.gz
(3.2 kB
view hashes)
Built Distribution
Close
Hashes for flask_fastconfig-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e3beb3136421827a6652b180612fd8c8523ac06a7a20be10a21ed25408a1024 |
|
MD5 | 2519482815254bec9a202a39a4cb7869 |
|
BLAKE2b-256 | 3b5d8b2cf40cd7887c9b8cf246f9873458ac58e681f76973f91bfbe43f762a2d |