setconfig


Namesetconfig JSON
Version 1.3.0 PyPI version JSON
download
home_pagehttps://github.com/abionics/setconfig
SummaryMulti-structure YAML config loader 🐍🔌
upload_time2023-12-14 20:50:08
maintainer
docs_urlNone
authorAlex Ermolaev
requires_python
licenseMIT
keywords config yaml dataclass pydantic init
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # setconfig 🔌

> [!TIP]
> Don't forget to star this repo if you like it! ⭐

Some developers prefer to use `@dataclass` while others prefer `BaseModel`.
This holy war is not going to end soon.
So now they can use the same loader and config file in different parts/microservices of one project.

Currently supported:
- [x] [`@dataclass`](https://docs.python.org/3/library/dataclasses.html)
- [x] Pydantic [`BaseModel`](https://docs.pydantic.dev/latest/api/base_model)
- [x] Python [`SimpleNamespace`](https://docs.python.org/3/library/types.html#types.SimpleNamespace) (dotted dict)


## Installation

```bash
pip install setconfig
```


## Usage sample

### Dataclass, full sample [here](examples/example_dataclass.py)

```python
from dataclasses import dataclass
from setconfig import load_config

@dataclass
class Node:
    host: str
    port: int

@dataclass
class Config:
    nodes: list[Node]

config = load_config('config.yaml', into=Config)

print(config)
# >>> Config(nodes=[Node(host='1.1.1.1', port=1000)])
print(config.nodes[0].host)
# >>> '1.1.1.1'
```

### Pydantic, full sample [here](examples/example_pydantic.py)

```python
from pydantic import BaseModel
from setconfig import load_config

class Node(BaseModel):
    host: str
    port: int

class Config(BaseModel):
    nodes: list[Node]

config = load_config('config.yaml', into=Config)

print(config)
# >>> Config(nodes=[Node(host='1.1.1.1', port=1000)])
print(config.nodes[0].host)
# >>> '1.1.1.1'
```

### SimpleNamespace, full sample [here](examples/example_simple.py)

```python
from setconfig import load_config

config = load_config('config.yaml')

print(config)
# >>> Config(nodes=[Node(host='1.1.1.1', port=1000)])
print(config.nodes[0].host)
# >>> '1.1.1.1'
```


## FAQ

### Why only YAML?

> There should be one-- and preferably only one --obvious way to do it
> 
> [(c) Zen of Python](https://peps.python.org/pep-0020/#the-zen-of-python)

### How to load from string/StringIO/etc?

Use `load_config_stream`

```python
from setconfig import load_config_stream

config = load_config_stream('done: true')
```

### I want to use structure from `X` package

Create an issue or PR :)


## More

PyPI: https://pypi.org/project/setconfig

Repository: https://github.com/abionics/setconfig

Developer: Alex Ermolaev (Abionics)

Email: abionics.dev@gmail.com

License: MIT (see LICENSE.txt)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/abionics/setconfig",
    "name": "setconfig",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "config yaml dataclass pydantic init",
    "author": "Alex Ermolaev",
    "author_email": "abionics.dev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/38/cf/0db7e49903ba52abe1c973275da36d611fceb5fad40acabbf4cf0e7a43cf/setconfig-1.3.0.tar.gz",
    "platform": null,
    "description": "# setconfig \ud83d\udd0c\n\n> [!TIP]\n> Don't forget to star this repo if you like it! \u2b50\n\nSome developers prefer to use `@dataclass` while others prefer `BaseModel`.\nThis holy war is not going to end soon.\nSo now they can use the same loader and config file in different parts/microservices of one project.\n\nCurrently supported:\n- [x] [`@dataclass`](https://docs.python.org/3/library/dataclasses.html)\n- [x] Pydantic [`BaseModel`](https://docs.pydantic.dev/latest/api/base_model)\n- [x] Python [`SimpleNamespace`](https://docs.python.org/3/library/types.html#types.SimpleNamespace) (dotted dict)\n\n\n## Installation\n\n```bash\npip install setconfig\n```\n\n\n## Usage sample\n\n### Dataclass, full sample [here](examples/example_dataclass.py)\n\n```python\nfrom dataclasses import dataclass\nfrom setconfig import load_config\n\n@dataclass\nclass Node:\n    host: str\n    port: int\n\n@dataclass\nclass Config:\n    nodes: list[Node]\n\nconfig = load_config('config.yaml', into=Config)\n\nprint(config)\n# >>> Config(nodes=[Node(host='1.1.1.1', port=1000)])\nprint(config.nodes[0].host)\n# >>> '1.1.1.1'\n```\n\n### Pydantic, full sample [here](examples/example_pydantic.py)\n\n```python\nfrom pydantic import BaseModel\nfrom setconfig import load_config\n\nclass Node(BaseModel):\n    host: str\n    port: int\n\nclass Config(BaseModel):\n    nodes: list[Node]\n\nconfig = load_config('config.yaml', into=Config)\n\nprint(config)\n# >>> Config(nodes=[Node(host='1.1.1.1', port=1000)])\nprint(config.nodes[0].host)\n# >>> '1.1.1.1'\n```\n\n### SimpleNamespace, full sample [here](examples/example_simple.py)\n\n```python\nfrom setconfig import load_config\n\nconfig = load_config('config.yaml')\n\nprint(config)\n# >>> Config(nodes=[Node(host='1.1.1.1', port=1000)])\nprint(config.nodes[0].host)\n# >>> '1.1.1.1'\n```\n\n\n## FAQ\n\n### Why only YAML?\n\n> There should be one-- and preferably only one --obvious way to do it\n> \n> [(c) Zen of Python](https://peps.python.org/pep-0020/#the-zen-of-python)\n\n### How to load from string/StringIO/etc?\n\nUse `load_config_stream`\n\n```python\nfrom setconfig import load_config_stream\n\nconfig = load_config_stream('done: true')\n```\n\n### I want to use structure from `X` package\n\nCreate an issue or PR :)\n\n\n## More\n\nPyPI: https://pypi.org/project/setconfig\n\nRepository: https://github.com/abionics/setconfig\n\nDeveloper: Alex Ermolaev (Abionics)\n\nEmail: abionics.dev@gmail.com\n\nLicense: MIT (see LICENSE.txt)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Multi-structure YAML config loader \ud83d\udc0d\ud83d\udd0c",
    "version": "1.3.0",
    "project_urls": {
        "Homepage": "https://github.com/abionics/setconfig"
    },
    "split_keywords": [
        "config",
        "yaml",
        "dataclass",
        "pydantic",
        "init"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38cf0db7e49903ba52abe1c973275da36d611fceb5fad40acabbf4cf0e7a43cf",
                "md5": "0837e2dd49a4aa46b1a00fc5063751c2",
                "sha256": "95481682e0224b3e3edf82081d99874087f63d0860a85a7f66bf8e14b10aa5e7"
            },
            "downloads": -1,
            "filename": "setconfig-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0837e2dd49a4aa46b1a00fc5063751c2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3952,
            "upload_time": "2023-12-14T20:50:08",
            "upload_time_iso_8601": "2023-12-14T20:50:08.694996Z",
            "url": "https://files.pythonhosted.org/packages/38/cf/0db7e49903ba52abe1c973275da36d611fceb5fad40acabbf4cf0e7a43cf/setconfig-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-14 20:50:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "abionics",
    "github_project": "setconfig",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "setconfig"
}
        
Elapsed time: 0.14973s