gifnoc


Namegifnoc JSON
Version 0.3.2 PyPI version JSON
download
home_pageNone
SummaryHandle configuration for multiple libraries
upload_time2024-04-18 02:07:40
maintainerNone
docs_urlNone
authorOlivier Breuleux
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Gifnoc

Gifnoc is a unified configuration system for Python modules.

The main objective of gifnoc is to unify configuration files, environment variables and command-line options, across multiple modules. For example, module A and module B can both define their own configuration models through gifnoc, map some environment variables to keys in that configuration, and then you may configure A and B in the same file.

Gifnoc also aims to validate configuration through a typed model based on dataclasses and implemented by the `apischema` package, a dependency of gifnoc.


## Features

* Typed configuration using dataclasses and `apischema`
* Use a single configuration tree for multiple libraries
* Multiple configuration files can be easily merged
* Easily embed configuration files in each other


## Example

**main.py**

```python
from dataclasses import dataclass
import gifnoc

@dataclass
class User:
    name: str
    email: str
    admin: bool

@dataclass
class Server:
    port: int = 8080
    host: str = "localhost"
    users: list[User]

server_config = gifnoc.define(
    field="server",
    model=Server,
    environ={
        APP_PORT="port",
        APP_HOST="host",
    }
)

if __name__ == "__main__":
    with gifnoc.cli(
        # Environment variable for the configuration path (defaults to GIFNOC_FILE)
        envvar="APP_CONFIG",
        # Command-line argument for the configuration path (can give multiple)
        config_argument="--config",
        # You can easily register command-line arguments to parts of the configuration
        options_map={"--port": "server.port"},
    ):
        # The `server_config` object will always refer to the `server` key in the
        # current configuration
        print("Port:", server_config.port)
```


**config.yaml**

```yaml
server:
  port: 1234
  host: here
  users:
    - name: Olivier
      email: ob@here
      admin: true
    # You can write a file path instead of an object
    - mysterio.yaml
```


**mysterio.yaml**

```yaml
- name: Mysterio
  email: me@myster.io
  admin: false
```


**Usage:**

```bash
python main.py --config config.yaml
APP_CONFIG=config.yaml python main.py
APP_PORT=8903 python main.py --config config.yaml
python main.py --config config.yaml --port 8903
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gifnoc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Olivier Breuleux",
    "author_email": "breuleux@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ee/81/59c2707155cd926bf023b4489d899c11c84be82abb6c5c26cd6ed9fe33aa/gifnoc-0.3.2.tar.gz",
    "platform": null,
    "description": "\n# Gifnoc\n\nGifnoc is a unified configuration system for Python modules.\n\nThe main objective of gifnoc is to unify configuration files, environment variables and command-line options, across multiple modules. For example, module A and module B can both define their own configuration models through gifnoc, map some environment variables to keys in that configuration, and then you may configure A and B in the same file.\n\nGifnoc also aims to validate configuration through a typed model based on dataclasses and implemented by the `apischema` package, a dependency of gifnoc.\n\n\n## Features\n\n* Typed configuration using dataclasses and `apischema`\n* Use a single configuration tree for multiple libraries\n* Multiple configuration files can be easily merged\n* Easily embed configuration files in each other\n\n\n## Example\n\n**main.py**\n\n```python\nfrom dataclasses import dataclass\nimport gifnoc\n\n@dataclass\nclass User:\n    name: str\n    email: str\n    admin: bool\n\n@dataclass\nclass Server:\n    port: int = 8080\n    host: str = \"localhost\"\n    users: list[User]\n\nserver_config = gifnoc.define(\n    field=\"server\",\n    model=Server,\n    environ={\n        APP_PORT=\"port\",\n        APP_HOST=\"host\",\n    }\n)\n\nif __name__ == \"__main__\":\n    with gifnoc.cli(\n        # Environment variable for the configuration path (defaults to GIFNOC_FILE)\n        envvar=\"APP_CONFIG\",\n        # Command-line argument for the configuration path (can give multiple)\n        config_argument=\"--config\",\n        # You can easily register command-line arguments to parts of the configuration\n        options_map={\"--port\": \"server.port\"},\n    ):\n        # The `server_config` object will always refer to the `server` key in the\n        # current configuration\n        print(\"Port:\", server_config.port)\n```\n\n\n**config.yaml**\n\n```yaml\nserver:\n  port: 1234\n  host: here\n  users:\n    - name: Olivier\n      email: ob@here\n      admin: true\n    # You can write a file path instead of an object\n    - mysterio.yaml\n```\n\n\n**mysterio.yaml**\n\n```yaml\n- name: Mysterio\n  email: me@myster.io\n  admin: false\n```\n\n\n**Usage:**\n\n```bash\npython main.py --config config.yaml\nAPP_CONFIG=config.yaml python main.py\nAPP_PORT=8903 python main.py --config config.yaml\npython main.py --config config.yaml --port 8903\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Handle configuration for multiple libraries",
    "version": "0.3.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b9f4708399bf9a57a66bede980223e407e0f900a61cbc7c7823052bb3cce437",
                "md5": "60c088f3e545dcd43cb8cfa28c6a9d23",
                "sha256": "dd73292aa270f34c25c39d9416cf97f77c0bdf2768436e1ece735a4ca13ea189"
            },
            "downloads": -1,
            "filename": "gifnoc-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "60c088f3e545dcd43cb8cfa28c6a9d23",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 20386,
            "upload_time": "2024-04-18T02:07:38",
            "upload_time_iso_8601": "2024-04-18T02:07:38.744710Z",
            "url": "https://files.pythonhosted.org/packages/6b/9f/4708399bf9a57a66bede980223e407e0f900a61cbc7c7823052bb3cce437/gifnoc-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ee8159c2707155cd926bf023b4489d899c11c84be82abb6c5c26cd6ed9fe33aa",
                "md5": "52c14d7cdf97cf46b7bdf4863d1900be",
                "sha256": "6cbc50c9fb8437090e9715c663059010a48d66f49fe9188ec0e245ee4f420cf3"
            },
            "downloads": -1,
            "filename": "gifnoc-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "52c14d7cdf97cf46b7bdf4863d1900be",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 16450,
            "upload_time": "2024-04-18T02:07:40",
            "upload_time_iso_8601": "2024-04-18T02:07:40.959598Z",
            "url": "https://files.pythonhosted.org/packages/ee/81/59c2707155cd926bf023b4489d899c11c84be82abb6c5c26cd6ed9fe33aa/gifnoc-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-18 02:07:40",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "gifnoc"
}
        
Elapsed time: 0.22829s