setconfig


Namesetconfig JSON
Version 1.3.1 PyPI version JSON
download
home_pagehttps://github.com/abionics/setconfig
SummaryMulti-structure YAML config loader 🐍🔌
upload_time2024-11-04 21:49:46
maintainerNone
docs_urlNone
authorAlex Ermolaev
requires_pythonNone
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": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "config yaml dataclass pydantic init",
    "author": "Alex Ermolaev",
    "author_email": "abionics.dev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/58/3e/b4038f029efc8c15f3a77834af804d0e9f320676201e42339ccb532e8386/setconfig-1.3.1.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.1",
    "project_urls": {
        "Homepage": "https://github.com/abionics/setconfig"
    },
    "split_keywords": [
        "config",
        "yaml",
        "dataclass",
        "pydantic",
        "init"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "583eb4038f029efc8c15f3a77834af804d0e9f320676201e42339ccb532e8386",
                "md5": "abe65962065cfa6be60b25e433047306",
                "sha256": "17a685100dfaf46098bbf01a7e5511f275ffb6cbd173b19bbf259069df9a1789"
            },
            "downloads": -1,
            "filename": "setconfig-1.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "abe65962065cfa6be60b25e433047306",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3997,
            "upload_time": "2024-11-04T21:49:46",
            "upload_time_iso_8601": "2024-11-04T21:49:46.464745Z",
            "url": "https://files.pythonhosted.org/packages/58/3e/b4038f029efc8c15f3a77834af804d0e9f320676201e42339ccb532e8386/setconfig-1.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-04 21:49:46",
    "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.76809s