snekcfg


Namesnekcfg JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/dhagrow/snekcfg
SummaryA minimalist wrapper for configparser.
upload_time2022-08-22 13:38:30
maintainer
docs_urlNone
authorMiguel Turner
requires_python
licenseMIT
keywords config configuration configparser options settings
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            `snekcfg` is a minimalist wrapper over
[configparser](https://docs.python.org/3/library/configparser.html) that offers
a more streamlined user experience.

Expected options and their types are predefined to prevent errors and minimize
repetitive logic within your codebase. This allows for simple, direct access to
your configuration within your program without worrying about typos or type
conversion.

## example.py

```python
import snekcfg

cfg = snekcfg.Config('example.cfg')

sct = cfg.section('server')
# the default value is used to automatically type as an int
sct.define('port', 8080)
# or, you can be explicit
sct.define('host', default='127.0.0.1', type=str)

# some common types like set[str] are already built-in,
# but here is an example of adding a codec for a new type.
# *type* can be a type object, or just a string like 'str_set'
cfg.register_type(
    type=set[str],
    encode=lambda v: ','.join(v),
    decode=lambda v: set(v.split(',')))

# sections can be accessed using dot notation (one level deep)
cfg.define('users.whitelist', default=set(), type=set[str])

# update values with dot notation
users = {'graham', 'john', 'terryg', 'eric', 'terryj', 'michael'}
cfg['users.whitelist'].update(users)
# or through the section
cfg.section('server')['port'] = 1337

# write to 'example.cfg'
cfg.write()

# let's tweak the config file externally
with open('example.cfg', 'r+') as f:
    s = f.read()
    f.seek(0)
    f.write(s.replace('1337', '1234'))

# read from 'example.cfg'
cfg.read()

# types are preserved
assert cfg['server.port'] == 1234
assert cfg['users.whitelist'] == users, users
```

## example.cfg

```ini
[server]
host = 127.0.0.1
port = 1337

[users]
whitelist = eric,graham,michael,john,terryg,terryj
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dhagrow/snekcfg",
    "name": "snekcfg",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "config,configuration,configparser,options,settings",
    "author": "Miguel Turner",
    "author_email": "cymrow@gmail.com",
    "download_url": "",
    "platform": "any",
    "description": "`snekcfg` is a minimalist wrapper over\n[configparser](https://docs.python.org/3/library/configparser.html) that offers\na more streamlined user experience.\n\nExpected options and their types are predefined to prevent errors and minimize\nrepetitive logic within your codebase. This allows for simple, direct access to\nyour configuration within your program without worrying about typos or type\nconversion.\n\n## example.py\n\n```python\nimport snekcfg\n\ncfg = snekcfg.Config('example.cfg')\n\nsct = cfg.section('server')\n# the default value is used to automatically type as an int\nsct.define('port', 8080)\n# or, you can be explicit\nsct.define('host', default='127.0.0.1', type=str)\n\n# some common types like set[str] are already built-in,\n# but here is an example of adding a codec for a new type.\n# *type* can be a type object, or just a string like 'str_set'\ncfg.register_type(\n    type=set[str],\n    encode=lambda v: ','.join(v),\n    decode=lambda v: set(v.split(',')))\n\n# sections can be accessed using dot notation (one level deep)\ncfg.define('users.whitelist', default=set(), type=set[str])\n\n# update values with dot notation\nusers = {'graham', 'john', 'terryg', 'eric', 'terryj', 'michael'}\ncfg['users.whitelist'].update(users)\n# or through the section\ncfg.section('server')['port'] = 1337\n\n# write to 'example.cfg'\ncfg.write()\n\n# let's tweak the config file externally\nwith open('example.cfg', 'r+') as f:\n    s = f.read()\n    f.seek(0)\n    f.write(s.replace('1337', '1234'))\n\n# read from 'example.cfg'\ncfg.read()\n\n# types are preserved\nassert cfg['server.port'] == 1234\nassert cfg['users.whitelist'] == users, users\n```\n\n## example.cfg\n\n```ini\n[server]\nhost = 127.0.0.1\nport = 1337\n\n[users]\nwhitelist = eric,graham,michael,john,terryg,terryj\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A minimalist wrapper for configparser.",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/dhagrow/snekcfg"
    },
    "split_keywords": [
        "config",
        "configuration",
        "configparser",
        "options",
        "settings"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5dec21cd3a9a929b6e2bea4292570e4a3fc2ae36dbe1fb77da3380803a5be5c7",
                "md5": "c32f57856cdeb7d030d4c49fd7aae87f",
                "sha256": "b60b00805b912e4e86f2376d7f9cd26701f26fdbffb0df2ebd47942822752149"
            },
            "downloads": -1,
            "filename": "snekcfg-0.1.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c32f57856cdeb7d030d4c49fd7aae87f",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 5011,
            "upload_time": "2022-08-22T13:38:30",
            "upload_time_iso_8601": "2022-08-22T13:38:30.284682Z",
            "url": "https://files.pythonhosted.org/packages/5d/ec/21cd3a9a929b6e2bea4292570e4a3fc2ae36dbe1fb77da3380803a5be5c7/snekcfg-0.1.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-08-22 13:38:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dhagrow",
    "github_project": "snekcfg",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "snekcfg"
}
        
Elapsed time: 0.09952s