Cyra is a simple config framework for Python.
Project description
Cyra is a simple config framework for Python.
Cyra’s ConfigBuilder makes it easy to specify your configuration. The config can be read from and written to a toml file.
If the config file does not exist, Cyra will generate a new one populated with initial values and annotated with helpful comments.
Checklist (development)
[X] Config builder
[X] Value fields (string, int, bool, list, dict)
[ ] Value verification
[X] Infinite nesting
[X] Comments
[X] Load/generate config from file
[X] Write config back to file
[ ] Sphinx Autodoc
How to use
import cyra
class MyConfig(cyra.Config):
builder = cyra.ConfigBuilder()
builder.comment('Cyra says hello')
msg = builder.define('msg', 'Hello World')
builder.comment('SQL Database settings')
builder.push('DATABASE')
builder.comment('DB server address')
server = builder.define('server', '192.168.1.1')
builder.comment('SQL port (default: 1443)')
port = builder.define('port', 1443)
builder.comment('Credentials')
user = builder.define('username', 'admin')
pwd = builder.define('password', 'my_secret_password')
builder.comment('DB connection enabled')
dben = builder.define('enabled', True)
builder.pop()
def __init__(self, cfg_file):
super().__init__(self.builder, cfg_file)
How to access your config values:
>>> cfg = MyConfig('config.toml')
>>> cfg.load_file()
>>> cfg.msg
'Hello World'
>>> cfg.msg = 'Bye bye World'
>>> cfg.save_file()
True
Here is the resulting config file:
msg = "Hello World" # Cyra says hello
[DATABASE] # SQL Database settings
server = "192.168.1.1" # DB server address
port = 1443 # SQL port (default: 1443)
username = "admin" # Credentials
password = "my_secret_password"
enabled = true # DB connection enabled
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Cyra-0.2.0.tar.gz
(5.3 kB
view hashes)
Built Distribution
Cyra-0.2.0-py3-none-any.whl
(6.1 kB
view hashes)