nanoconf


Namenanoconf JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryThe tiny opinionated config loader.
upload_time2023-10-09 04:50:34
maintainer
docs_urlNone
author
requires_python>=3.11
license
keywords nanoconf config configuration settings
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            NanoConf
========
NanoConf is a tiny, opinionated, and easy to use configuration library for Python. It is designed to be used in small to medium sized projects where a full blown configuration library is overkill.

Installation
------------
```bash
pip install nanoconf
```

Usage
-----
```python
from nanoconf import NanoConf
# or if NanoConf if too long of a name
from nanoconf import NC

# Create a new configuration object
config = NanoConf("/path/to/config.nconf")

# Use the configuration object
print(config["key"])
# Since all values are also loaded as attributes, you can also do
print(config.key)
```

Configuration File Format
-------------------------
NanoConf uses a simple configuration file format that is easy to read and write.
Each File is YAML formatted and contains a single top-level dictionary.
Even though the top-level must be a dictionary, you can nest dictionaries and lists as deep as you want.
Each config file also must have the .nconf extension. This ensures that NanoConf will only load files that are meant to be configuration files.
```yaml
key: value
test: 1
overriden: false
things:
    - thing1
    - thing2
    - thing3
top:
    v1: 1
    middle:
        v2: 2
        inner:
            v3: 3
            deep:
                v4: 4
```
If you have multiple config files you want to load into a single config object, you can put them all in the same directory and pass that directory to NanoConf.
NanoConf will automatically place sub-files by their filename as an attribute of the parent file.
The contents of that file will be accessible as you'd expect under the corresponding filename attribute.

```
<project root>
conf_dir
  |__ cfg1.nconf
  |__ cfg2.nconf
  |__ cfg3.nconf
```

```python
# load an entire directory
proj_config = NanoConf("/path/to/conf_dir")
print(proj_config.cfg1.test)
```

Or you can import additional files or directories from within any config file by using the `_import` keyword.
```yaml
# main.nconf
_import:
    - /path/to/project/more_config
key: value
test: 1
```

```
<project root>
main.nconf
more_config
  |__ subcfg1.nconf
  |__ subcfg2.nconf
  |__ subcfg3.nconf
```

```python
# loading the main config file will also load the sub-configs
proj_config = NanoConf("/path/to/project/main.nconf")
print(proj_config.more_config.subcfg1.test)
```
Notice how the directory structure was also maintained in the attribute path. This makes it easier to find the file that a value came from.

Environment Variables
---------------------
NanoConf supports environment variables either as overrides to existing values or as additions to the loaded config.
Envars are evaluated on a per-file basis, so you can have different envars for different config files.
The way we manage this is by having a special `_envar_prefix` key in the config file.
**Note:** NanoConf will not modify the case of any environment varable name or value. It is up to you to ensure that the case is correct.
```yaml
_envar_prefix: myapp
key: value
overrideme: original
```
```bash
export myapp_overrideme=changed
```
```python
config = NanoConf("/path/to/config.nconf")
print(config.overrideme)
```

You can also pass complex data structures as JSON strings in environment variables.
```bash
export myapp_abc='{"a": 1, "b": 2, "c": 3}'
```
```python
config = NanoConf("/path/to/config.nconf")
print(config.abc.b)
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "nanoconf",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "nanoconf,config,configuration,settings",
    "author": "",
    "author_email": "Jacob J Callahan <jacob.callahan05@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/21/07/af04f1aa914266a472cde6a8f4b9a6d9fe70622f6bc0da86c1b323ad92ce/nanoconf-1.0.0.tar.gz",
    "platform": "any",
    "description": "NanoConf\n========\nNanoConf is a tiny, opinionated, and easy to use configuration library for Python. It is designed to be used in small to medium sized projects where a full blown configuration library is overkill.\n\nInstallation\n------------\n```bash\npip install nanoconf\n```\n\nUsage\n-----\n```python\nfrom nanoconf import NanoConf\n# or if NanoConf if too long of a name\nfrom nanoconf import NC\n\n# Create a new configuration object\nconfig = NanoConf(\"/path/to/config.nconf\")\n\n# Use the configuration object\nprint(config[\"key\"])\n# Since all values are also loaded as attributes, you can also do\nprint(config.key)\n```\n\nConfiguration File Format\n-------------------------\nNanoConf uses a simple configuration file format that is easy to read and write.\nEach File is YAML formatted and contains a single top-level dictionary.\nEven though the top-level must be a dictionary, you can nest dictionaries and lists as deep as you want.\nEach config file also must have the .nconf extension. This ensures that NanoConf will only load files that are meant to be configuration files.\n```yaml\nkey: value\ntest: 1\noverriden: false\nthings:\n    - thing1\n    - thing2\n    - thing3\ntop:\n    v1: 1\n    middle:\n        v2: 2\n        inner:\n            v3: 3\n            deep:\n                v4: 4\n```\nIf you have multiple config files you want to load into a single config object, you can put them all in the same directory and pass that directory to NanoConf.\nNanoConf will automatically place sub-files by their filename as an attribute of the parent file.\nThe contents of that file will be accessible as you'd expect under the corresponding filename attribute.\n\n```\n<project root>\nconf_dir\n  |__ cfg1.nconf\n  |__ cfg2.nconf\n  |__ cfg3.nconf\n```\n\n```python\n# load an entire directory\nproj_config = NanoConf(\"/path/to/conf_dir\")\nprint(proj_config.cfg1.test)\n```\n\nOr you can import additional files or directories from within any config file by using the `_import` keyword.\n```yaml\n# main.nconf\n_import:\n    - /path/to/project/more_config\nkey: value\ntest: 1\n```\n\n```\n<project root>\nmain.nconf\nmore_config\n  |__ subcfg1.nconf\n  |__ subcfg2.nconf\n  |__ subcfg3.nconf\n```\n\n```python\n# loading the main config file will also load the sub-configs\nproj_config = NanoConf(\"/path/to/project/main.nconf\")\nprint(proj_config.more_config.subcfg1.test)\n```\nNotice how the directory structure was also maintained in the attribute path. This makes it easier to find the file that a value came from.\n\nEnvironment Variables\n---------------------\nNanoConf supports environment variables either as overrides to existing values or as additions to the loaded config.\nEnvars are evaluated on a per-file basis, so you can have different envars for different config files.\nThe way we manage this is by having a special `_envar_prefix` key in the config file.\n**Note:** NanoConf will not modify the case of any environment varable name or value. It is up to you to ensure that the case is correct.\n```yaml\n_envar_prefix: myapp\nkey: value\noverrideme: original\n```\n```bash\nexport myapp_overrideme=changed\n```\n```python\nconfig = NanoConf(\"/path/to/config.nconf\")\nprint(config.overrideme)\n```\n\nYou can also pass complex data structures as JSON strings in environment variables.\n```bash\nexport myapp_abc='{\"a\": 1, \"b\": 2, \"c\": 3}'\n```\n```python\nconfig = NanoConf(\"/path/to/config.nconf\")\nprint(config.abc.b)\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "The tiny opinionated config loader.",
    "version": "1.0.0",
    "project_urls": {
        "Repository": "https://github.com/JacobCallahan/nanoconf"
    },
    "split_keywords": [
        "nanoconf",
        "config",
        "configuration",
        "settings"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eba31f8d53a1d016b479ef0f6a185ad745c4f1beb44b56afcca56e46468b7743",
                "md5": "c039c84868de01c681231e91d3e13058",
                "sha256": "f4846b1aa0bab538418d552e2cfd6b8210d1e73368c044f2d4aef921f112ef01"
            },
            "downloads": -1,
            "filename": "nanoconf-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c039c84868de01c681231e91d3e13058",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 3929,
            "upload_time": "2023-10-09T04:50:32",
            "upload_time_iso_8601": "2023-10-09T04:50:32.837103Z",
            "url": "https://files.pythonhosted.org/packages/eb/a3/1f8d53a1d016b479ef0f6a185ad745c4f1beb44b56afcca56e46468b7743/nanoconf-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2107af04f1aa914266a472cde6a8f4b9a6d9fe70622f6bc0da86c1b323ad92ce",
                "md5": "4eb0bc2eb2c016737bb474ea5b43dfeb",
                "sha256": "b196caa30674ed94470137d1918e0c35fdce7b9ca9a98ba362c32e6191c7e7e2"
            },
            "downloads": -1,
            "filename": "nanoconf-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4eb0bc2eb2c016737bb474ea5b43dfeb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 6870,
            "upload_time": "2023-10-09T04:50:34",
            "upload_time_iso_8601": "2023-10-09T04:50:34.527096Z",
            "url": "https://files.pythonhosted.org/packages/21/07/af04f1aa914266a472cde6a8f4b9a6d9fe70622f6bc0da86c1b323ad92ce/nanoconf-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-09 04:50:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "JacobCallahan",
    "github_project": "nanoconf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "nanoconf"
}
        
Elapsed time: 0.14970s