Skip to main content

YAML config parser

Project description

comfyconf

What is it for?

Using YAML configuration files for python require less boilerplate code, and accessing the values by dot notation.

Installation

pip install comfyconf

Usage

Basic

Create a config file in YAML and name it foo.yaml:

test:
  title: 'test' 
  ip: '127.0.0.1' 
  port: 5000

production:
  title: 'My amazing server' 
  ip: '1234.255.255.1' 
  port: 1234

Now, load it using make_config:

>>> from comfyconf import make_config   
>>> config = make_config("foo.yaml")
>>> config.test.ip
'127.0.0.1'
>>> config.production.port
1234  

Note that numerical keys are not allowed (even if they're strings in YAML), doing so will raise a ValueError.

Using ruamel.yaml as parser instead of pyyaml

If you prefer ruamel.yaml or need to parse YAML 1.2 document you can specify `"ruamel"`` as the reader:

>>> config = make_config("foo.yaml", reader="ruamel")

Validate configuration against a schema

If you need to be validate that the configuration is compatible with a schema, you can use validate_config:

First, create a schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "$defs": {  
    "connection": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "title": {"type": "string"},
        "ip": {"type": "string", "format":"ipv4"},
        "port": { "type": "integer", "minimum": 1, "maximum": 65535}
      },
      "required": ["title", "ip", "port"]          
    }
  },
  "type": "object",
  "properties": {
    "test": {"$ref": "#/$defs/connection"},
    "production": {"$ref": "#/$defs/connection"}
  }
}
>>> from comfyconf import make_config, validate_config   
>>> config = make_config("foo.yaml", reader="ruamel")
>>> validate_config(config, "schema.json", validator='json')

Currently, json-schema (validator='json') is the default but yamale schema can also be used (validator='yamale') if yamale is installed.

Contribute

If you find a bug or have a feature request, please raise on issue on Github.

Contributions are more than welcome, but please:

  1. Write unittest (pytest)
  2. Write Numpy styled docstrings

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comfyconf-0.0.2.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

comfyconf-0.0.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file comfyconf-0.0.2.tar.gz.

File metadata

  • Download URL: comfyconf-0.0.2.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for comfyconf-0.0.2.tar.gz
Algorithm Hash digest
SHA256 dcc9e278132ae0aa1dba7ff77abcc165cae231cdfb04afaa8b6d75d327637263
MD5 41c4c62f02949b74412e8d7483ba7af6
BLAKE2b-256 ffda593b01b7e6e2c09c9927b121cef2dacd08fcb3f111811ce3fa0928c9d693

See more details on using hashes here.

File details

Details for the file comfyconf-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: comfyconf-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for comfyconf-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ae5e35bc3e5b33f6612a31f79f87827aa833c95a15ba7064e3acc03948b5e757
MD5 3de758ba985ba7571d1add753f89926f
BLAKE2b-256 7076e0882930b714c949902053439e71646094c7aea53a32f4a639421c4f4ec1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page