tomfig


Nametomfig JSON
Version 0.1.0 PyPI version JSON
download
home_page
Summary
upload_time2023-06-03 21:11:05
maintainer
docs_urlNone
authorAnthony Mugendi
requires_python>=3.8,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!--
 Copyright (c) 2023 Anthony Mugendi
 
 This software is released under the MIT License.
 https://opensource.org/licenses/MIT
-->

# TOMFIG - Toml Config
The simplest TOML config manager for python!

This module borrows a little from [config](https://www.npmjs.com/package/config). The only argument needed during initialization is the `config_path`. 

```python
from tomfig import Config

# defaults to [cwd]/config
config = Config(config_path='/dir/with/config_files')

```

The module then loads configuration files and merges down the configs in the following order.

1. **`default.toml`**
2. **[environment_config].toml** where environment is whatever you pass to your script via the `ENV` environment variable. Default is **`development.toml`**

## Accessing Config Values
There are two ways of accessing config values.

Imagine we have the following config file:
```toml
[APP]
name="My App"

[TOOLS.language-support]
python=">3.8"

[SERVER.API]
domain="localhost:3000/default"
```

### 1. Direct/Data Access
You can access config values directly using dot notation via the `data` property as follows.

```python
config.data.APP.name 
# "My App"
```

However, this method is discouraged on production. This is because, if a key is missing, it returns `None` instead of throwing an error. 

That behaviour is however intentional as it allows us an eay way to check is a config value exists. For example:

```python
# Check if our app has a name
if not config.data.APP.name:
    # Use AI to generate and set APP name 
```

### 2. Safe/Get Access

This is the preferred method to access config values.  This method immediately throws if a certain value is missing.

```python
config.get("SERVER.API.domain")
# "localhost:3000/development"
```

Have a look at the tests for examples.

# Thoughts
I have not implemented a `.set()` method and don't plan to. It is my considered view that configs should be static and only changed in the config files to ensure code functions in a predictable, easy to debug manner.
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "tomfig",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Anthony Mugendi",
    "author_email": "ngurumugz@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/90/27/c7a6bdfec013027e36f58bd1fa9b7d15d30880d04de65a09300bb37f3296/tomfig-0.1.0.tar.gz",
    "platform": null,
    "description": "<!--\n Copyright (c) 2023 Anthony Mugendi\n \n This software is released under the MIT License.\n https://opensource.org/licenses/MIT\n-->\n\n# TOMFIG - Toml Config\nThe simplest TOML config manager for python!\n\nThis module borrows a little from [config](https://www.npmjs.com/package/config). The only argument needed during initialization is the `config_path`. \n\n```python\nfrom tomfig import Config\n\n# defaults to [cwd]/config\nconfig = Config(config_path='/dir/with/config_files')\n\n```\n\nThe module then loads configuration files and merges down the configs in the following order.\n\n1. **`default.toml`**\n2. **[environment_config].toml** where environment is whatever you pass to your script via the `ENV` environment variable. Default is **`development.toml`**\n\n## Accessing Config Values\nThere are two ways of accessing config values.\n\nImagine we have the following config file:\n```toml\n[APP]\nname=\"My App\"\n\n[TOOLS.language-support]\npython=\">3.8\"\n\n[SERVER.API]\ndomain=\"localhost:3000/default\"\n```\n\n### 1. Direct/Data Access\nYou can access config values directly using dot notation via the `data` property as follows.\n\n```python\nconfig.data.APP.name \n# \"My App\"\n```\n\nHowever, this method is discouraged on production. This is because, if a key is missing, it returns `None` instead of throwing an error. \n\nThat behaviour is however intentional as it allows us an eay way to check is a config value exists. For example:\n\n```python\n# Check if our app has a name\nif not config.data.APP.name:\n    # Use AI to generate and set APP name \n```\n\n### 2. Safe/Get Access\n\nThis is the preferred method to access config values.  This method immediately throws if a certain value is missing.\n\n```python\nconfig.get(\"SERVER.API.domain\")\n# \"localhost:3000/development\"\n```\n\nHave a look at the tests for examples.\n\n# Thoughts\nI have not implemented a `.set()` method and don't plan to. It is my considered view that configs should be static and only changed in the config files to ensure code functions in a predictable, easy to debug manner.",
    "bugtrack_url": null,
    "license": "",
    "summary": "",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "def1552f150751eb9d636f3a08677f3e648ff3b297ad4b5198aec35e83efa40d",
                "md5": "49b3bafc90cd35abb76d5ffeaa2e700d",
                "sha256": "ed4167ca4c93e990f94108091e15072afa2efff32d16c295d9f8dd916f67f7eb"
            },
            "downloads": -1,
            "filename": "tomfig-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "49b3bafc90cd35abb76d5ffeaa2e700d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 4290,
            "upload_time": "2023-06-03T21:11:03",
            "upload_time_iso_8601": "2023-06-03T21:11:03.816556Z",
            "url": "https://files.pythonhosted.org/packages/de/f1/552f150751eb9d636f3a08677f3e648ff3b297ad4b5198aec35e83efa40d/tomfig-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9027c7a6bdfec013027e36f58bd1fa9b7d15d30880d04de65a09300bb37f3296",
                "md5": "ae63b4b2a65b52c907067891bc36f657",
                "sha256": "7b973dda53c88be860c621d5cb19145dc8bdf5344528de254d7c5aec78975aca"
            },
            "downloads": -1,
            "filename": "tomfig-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ae63b4b2a65b52c907067891bc36f657",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 3460,
            "upload_time": "2023-06-03T21:11:05",
            "upload_time_iso_8601": "2023-06-03T21:11:05.975640Z",
            "url": "https://files.pythonhosted.org/packages/90/27/c7a6bdfec013027e36f58bd1fa9b7d15d30880d04de65a09300bb37f3296/tomfig-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-03 21:11:05",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "tomfig"
}
        
Elapsed time: 0.15018s