confdantic


Nameconfdantic JSON
Version 0.0.5 PyPI version JSON
download
home_pageNone
SummaryConfdantic is a Python library that enhances Pydantic's capabilities for working with JSON, YAML, and TOML formats. It preserves field descriptions as comments when serializing to YAML or TOML, making it great for generating user-friendly configuration files.
upload_time2024-10-17 16:53:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords config yaml toml configuration-management yaml-configuration pydantic pydantic-configuration toml-configuration
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Confdantic
[![Tests](https://github.com/zigai/confdantic/actions/workflows/tests.yml/badge.svg)](https://github.com/zigai/confdantic/actions/workflows/tests.yml)
[![PyPI version](https://badge.fury.io/py/confdantic.svg)](https://badge.fury.io/py/confdantic)
![Supported versions](https://img.shields.io/badge/python-3.10+-blue.svg)
[![Downloads](https://static.pepy.tech/badge/confdantic)](https://pepy.tech/project/confdantic)
[![license](https://img.shields.io/github/license/zigai/confdantic.svg)](https://github.com/zigai/confdantic/blob/master/LICENSE)

`Confdantic` is a Python library that enhances Pydantic's capabilities for working with JSON, YAML, and TOML formats.
It preserves field descriptions as comments when serializing to YAML or TOML, making it great for generating user-friendly configuration files.

## Installation
#### From PyPi
```
pip install confdantic
```
#### From source
```
pip install git+https://github.com/zigai/confdantic.git
```
## Example
```python
from typing import Literal
from pydantic import Field
from confdantic import Confdantic

class DatabaseConfig(Confdantic):
    host: str = Field(
        "localhost",
        description="The hostname or IP address of the database server",
    )
    port: int = Field(
        5432,
        description="The port number on which the database server is listening.",
    )
    username: str
    password: str

class ApplicationConfig(Confdantic):
    debug: bool = Field(False, description="Enable debug mode")
    log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR"] = Field(
        "INFO", description="Logging level"
    )
    database: DatabaseConfig
    allowed_hosts: list[str] = Field(
        default_factory=list,
        description="A list of host/domain names that this application can serve.",
    )

config = ApplicationConfig(
    database=DatabaseConfig(username="admin", password="secret"),
    allowed_hosts=["example.com"],
)
config.save("config.yaml", comments=True)
config.save("config.toml", comments=True)
```
`config.yaml`
```yaml
debug: false  # Enable debug mode
log_level: INFO # Logging level | choices: DEBUG, INFO, WARNING, ERROR
database:
  host: localhost  # The hostname or IP address of the database server
  port: 5432 # The port number on which the database server is listening.
  username: admin
  password: secret
allowed_hosts:  # A list of host/domain names that this application can serve.
  - example.com
```
`config.toml`
```toml
debug = false # Enable debug mode
log_level = "INFO" # Logging level | choices: DEBUG, INFO, WARNING, ERROR
allowed_hosts = ["example.com"] # A list of host/domain names that this application can serve.

[database]
host = "localhost" # The hostname or IP address of the database server
port = 5432 # The port number on which the database server is listening.
username = "admin"
password = "secret"
```
## License
[MIT License](https://github.com/zigai/confdantic/blob/master/LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "confdantic",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "config, yaml, toml, configuration-management, yaml-configuration, pydantic, pydantic-configuration, toml-configuration",
    "author": null,
    "author_email": "\u017diga Ivan\u0161ek <ziga.ivansek@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/93/d4/fa5b8d0dc372bade2a1ee63980ea480c9f9a6095d2bfff392d0bc5ae6c69/confdantic-0.0.5.tar.gz",
    "platform": null,
    "description": "# Confdantic\n[![Tests](https://github.com/zigai/confdantic/actions/workflows/tests.yml/badge.svg)](https://github.com/zigai/confdantic/actions/workflows/tests.yml)\n[![PyPI version](https://badge.fury.io/py/confdantic.svg)](https://badge.fury.io/py/confdantic)\n![Supported versions](https://img.shields.io/badge/python-3.10+-blue.svg)\n[![Downloads](https://static.pepy.tech/badge/confdantic)](https://pepy.tech/project/confdantic)\n[![license](https://img.shields.io/github/license/zigai/confdantic.svg)](https://github.com/zigai/confdantic/blob/master/LICENSE)\n\n`Confdantic` is a Python library that enhances Pydantic's capabilities for working with JSON, YAML, and TOML formats.\nIt preserves field descriptions as comments when serializing to YAML or TOML, making it great for generating user-friendly configuration files.\n\n## Installation\n#### From PyPi\n```\npip install confdantic\n```\n#### From source\n```\npip install git+https://github.com/zigai/confdantic.git\n```\n## Example\n```python\nfrom typing import Literal\nfrom pydantic import Field\nfrom confdantic import Confdantic\n\nclass DatabaseConfig(Confdantic):\n    host: str = Field(\n        \"localhost\",\n        description=\"The hostname or IP address of the database server\",\n    )\n    port: int = Field(\n        5432,\n        description=\"The port number on which the database server is listening.\",\n    )\n    username: str\n    password: str\n\nclass ApplicationConfig(Confdantic):\n    debug: bool = Field(False, description=\"Enable debug mode\")\n    log_level: Literal[\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\"] = Field(\n        \"INFO\", description=\"Logging level\"\n    )\n    database: DatabaseConfig\n    allowed_hosts: list[str] = Field(\n        default_factory=list,\n        description=\"A list of host/domain names that this application can serve.\",\n    )\n\nconfig = ApplicationConfig(\n    database=DatabaseConfig(username=\"admin\", password=\"secret\"),\n    allowed_hosts=[\"example.com\"],\n)\nconfig.save(\"config.yaml\", comments=True)\nconfig.save(\"config.toml\", comments=True)\n```\n`config.yaml`\n```yaml\ndebug: false  # Enable debug mode\nlog_level: INFO # Logging level | choices: DEBUG, INFO, WARNING, ERROR\ndatabase:\n  host: localhost  # The hostname or IP address of the database server\n  port: 5432 # The port number on which the database server is listening.\n  username: admin\n  password: secret\nallowed_hosts:  # A list of host/domain names that this application can serve.\n  - example.com\n```\n`config.toml`\n```toml\ndebug = false # Enable debug mode\nlog_level = \"INFO\" # Logging level | choices: DEBUG, INFO, WARNING, ERROR\nallowed_hosts = [\"example.com\"] # A list of host/domain names that this application can serve.\n\n[database]\nhost = \"localhost\" # The hostname or IP address of the database server\nport = 5432 # The port number on which the database server is listening.\nusername = \"admin\"\npassword = \"secret\"\n```\n## License\n[MIT License](https://github.com/zigai/confdantic/blob/master/LICENSE)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Confdantic is a Python library that enhances Pydantic's capabilities for working with JSON, YAML, and TOML formats. It preserves field descriptions as comments when serializing to YAML or TOML, making it great for generating user-friendly configuration files.",
    "version": "0.0.5",
    "project_urls": {
        "Repository": "https://github.com/zigai/confdantic"
    },
    "split_keywords": [
        "config",
        " yaml",
        " toml",
        " configuration-management",
        " yaml-configuration",
        " pydantic",
        " pydantic-configuration",
        " toml-configuration"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "419622e04e817e161bf5760c0787c8add7fc862b6414cd52e78f4a5605001141",
                "md5": "b22e2c077490df27d72970f2c0f72d6d",
                "sha256": "49c65f530053e55fc38ae96f60cffe2e8b936b6a07e1e0e452e1148ecf8d2691"
            },
            "downloads": -1,
            "filename": "confdantic-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b22e2c077490df27d72970f2c0f72d6d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 5753,
            "upload_time": "2024-10-17T16:53:40",
            "upload_time_iso_8601": "2024-10-17T16:53:40.290150Z",
            "url": "https://files.pythonhosted.org/packages/41/96/22e04e817e161bf5760c0787c8add7fc862b6414cd52e78f4a5605001141/confdantic-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "93d4fa5b8d0dc372bade2a1ee63980ea480c9f9a6095d2bfff392d0bc5ae6c69",
                "md5": "29e75eff418c5fcf02fca428e66ded23",
                "sha256": "a67e1997aa96f759fe082b26ed57ecd03c4d14de86f31034d342e4efc869aac9"
            },
            "downloads": -1,
            "filename": "confdantic-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "29e75eff418c5fcf02fca428e66ded23",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 6592,
            "upload_time": "2024-10-17T16:53:41",
            "upload_time_iso_8601": "2024-10-17T16:53:41.825685Z",
            "url": "https://files.pythonhosted.org/packages/93/d4/fa5b8d0dc372bade2a1ee63980ea480c9f9a6095d2bfff392d0bc5ae6c69/confdantic-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-17 16:53:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zigai",
    "github_project": "confdantic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "confdantic"
}
        
Elapsed time: 0.99255s