confboy1


Nameconfboy1 JSON
Version 1.1.2 PyPI version JSON
download
home_page
SummaryBetter configs with TOML support
upload_time2024-01-10 05:47:35
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT License Copyright (c) 2024 Gleb Stiblo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords toml config confboy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Confboy

Better configs with TOML support.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install confboy.

```bash
pip install confboy
```

## Usage

```python
import confboy


base_config = {
    'nested': {
        'one': 1,
        'two': 2,
    },
    'three': 3,
}

config = confboy.Config(base_config)

config.nested.one  # Returns `1`
config.three       # Returns `3`
```

Although it is advised not to change the config
during runtime, it is also possible:

```python
config.nested.one = 10
config.nested.one  # Returns `10`

config.new_nested = {'one': 1}
config.new_nested.one  # Returns `10`
```

Confboy also supports dynamic values
that can use other values from the same config.
You can use it to build connection URLs or whatever.
Shines with changing config during runtime:
change `config.postgres.user` and `config.postgres.url`
will be rebuilt on every query if it's a callable.
You can do various things with it including mapping
and filtering values the app got from the TOML config,
cast types, whatever comes to your mind.
Callables work on any nested level.

```python
config = confboy.Config({
    'a': {'a': 1},
    'b': 2,
    'a_plus_b': 'callable:add',  # Tell confboy to call `add` from provided callables
})


def add():
    return config.a.a + config.b


config.register_callable(add)
config.a_plus_b  # Returns 3
```

Confboy can take values from TOML files as well.
Provided config will be merged over base config.

```toml
# config.toml

[nested]
one = 1
two = 2

not = "nested"
```

```python
config = confboy.Config(toml_config_path='config.toml')
config.nested.one  # Returns 1
config.not         # Returns 'nested'
```

Confboy's merges are __soft__: if the value
is present in the config but not in patch,
it won't be deleted from the config.
It supports value deletion and everything.
Just try it out or check the source code!


## Async functions as callables

Currently `confboy` does not support asynchronous functions
as callables. That would bring interface inconsistency
like `await config.foo` vs `config.foo`. You can wrap
your asynchronous function like that:

```python
config.register_callable(
    functools.partial(asyncio.run, async_func()))
```

Although that'd block the event loop.



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "confboy1",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "toml,config,confboy",
    "author": "",
    "author_email": "Euromancer <info@realpython.com>",
    "download_url": "https://files.pythonhosted.org/packages/10/bc/30f7143061006e76ef68881a5e9b84bceb6a3c8e3eb5ada35cfe6dece3ae/confboy1-1.1.2.tar.gz",
    "platform": null,
    "description": "# Confboy\n\nBetter configs with TOML support.\n\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install confboy.\n\n```bash\npip install confboy\n```\n\n## Usage\n\n```python\nimport confboy\n\n\nbase_config = {\n    'nested': {\n        'one': 1,\n        'two': 2,\n    },\n    'three': 3,\n}\n\nconfig = confboy.Config(base_config)\n\nconfig.nested.one  # Returns `1`\nconfig.three       # Returns `3`\n```\n\nAlthough it is advised not to change the config\nduring runtime, it is also possible:\n\n```python\nconfig.nested.one = 10\nconfig.nested.one  # Returns `10`\n\nconfig.new_nested = {'one': 1}\nconfig.new_nested.one  # Returns `10`\n```\n\nConfboy also supports dynamic values\nthat can use other values from the same config.\nYou can use it to build connection URLs or whatever.\nShines with changing config during runtime:\nchange `config.postgres.user` and `config.postgres.url`\nwill be rebuilt on every query if it's a callable.\nYou can do various things with it including mapping\nand filtering values the app got from the TOML config,\ncast types, whatever comes to your mind.\nCallables work on any nested level.\n\n```python\nconfig = confboy.Config({\n    'a': {'a': 1},\n    'b': 2,\n    'a_plus_b': 'callable:add',  # Tell confboy to call `add` from provided callables\n})\n\n\ndef add():\n    return config.a.a + config.b\n\n\nconfig.register_callable(add)\nconfig.a_plus_b  # Returns 3\n```\n\nConfboy can take values from TOML files as well.\nProvided config will be merged over base config.\n\n```toml\n# config.toml\n\n[nested]\none = 1\ntwo = 2\n\nnot = \"nested\"\n```\n\n```python\nconfig = confboy.Config(toml_config_path='config.toml')\nconfig.nested.one  # Returns 1\nconfig.not         # Returns 'nested'\n```\n\nConfboy's merges are __soft__: if the value\nis present in the config but not in patch,\nit won't be deleted from the config.\nIt supports value deletion and everything.\nJust try it out or check the source code!\n\n\n## Async functions as callables\n\nCurrently `confboy` does not support asynchronous functions\nas callables. That would bring interface inconsistency\nlike `await config.foo` vs `config.foo`. You can wrap\nyour asynchronous function like that:\n\n```python\nconfig.register_callable(\n    functools.partial(asyncio.run, async_func()))\n```\n\nAlthough that'd block the event loop.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Gleb Stiblo  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Better configs with TOML support",
    "version": "1.1.2",
    "project_urls": {
        "Homepage": "https://github.com/UlfR/confboy"
    },
    "split_keywords": [
        "toml",
        "config",
        "confboy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17e74164286ea5103940f686404d8fb551cbf2fd26bf555369f491c7dd470687",
                "md5": "8eb372aa0ccefa139a55a9ec22f3c1c5",
                "sha256": "ed82e2495309cb3c59e5f2a4b9bbdeb896ee26aaf198baccaa51952f018c31ec"
            },
            "downloads": -1,
            "filename": "confboy1-1.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8eb372aa0ccefa139a55a9ec22f3c1c5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4527,
            "upload_time": "2024-01-10T05:47:33",
            "upload_time_iso_8601": "2024-01-10T05:47:33.620631Z",
            "url": "https://files.pythonhosted.org/packages/17/e7/4164286ea5103940f686404d8fb551cbf2fd26bf555369f491c7dd470687/confboy1-1.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "10bc30f7143061006e76ef68881a5e9b84bceb6a3c8e3eb5ada35cfe6dece3ae",
                "md5": "b273d3e53b4ae3c89e50ec5f8883e33d",
                "sha256": "4f1d2468d1ce777682b25fa6b51675496481ef89bad06412aebe46ada9eea77e"
            },
            "downloads": -1,
            "filename": "confboy1-1.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b273d3e53b4ae3c89e50ec5f8883e33d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 3901,
            "upload_time": "2024-01-10T05:47:35",
            "upload_time_iso_8601": "2024-01-10T05:47:35.606002Z",
            "url": "https://files.pythonhosted.org/packages/10/bc/30f7143061006e76ef68881a5e9b84bceb6a3c8e3eb5ada35cfe6dece3ae/confboy1-1.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-10 05:47:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "UlfR",
    "github_project": "confboy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "confboy1"
}
        
Elapsed time: 0.34377s