New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

confclasses

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

confclasses

A simple wrapper around dataclasses, for general configuration

pipPyPI
Version
0.0.1
Maintainers
3

Confclasses

Create dataclass-style classes that can be used for configuring a Python tool. The idea is to handle loading and saving the config from files while allowing simpler IDE usage with the config. We don't need 90% of the features in dataclasses, so we make the API easier.

The module is designed to have a global config object that is instantiated at the start and then loaded dynamically later. Please see the common usage section for an example.

confclasses_comments is also shipped with this tool. It uses ruamel.yaml to add comments and ast to get the "docstring" of the annotations (fields) in the config classes.

Common usage

Create a config.py to store the config.

# config.py
@confclass
class RepeatingConfig:
    test: str
    default1: int = 123
    
@confclass
class NestedConfig:
    field1: str = "foo"
    field2: str = "bar"
    """ test document for field 2 """
    hashed_field3: RepeatingConfig = RepeatingConfig(test="nested")

@confclass
class ExampleConfig:
    nested: NestedConfig
    field3: int = 42
    """ test document for field 3 """
    hashed_field1: list = ["test", "items"]
    hashed_field2: dict = {"key1": "value1"}
    hashed_field4: RepeatingConfig = RepeatingConfig(test="base")

config = ExampleConfig()

Loading it at the start

# main.py
from confclasses import load_config
from config import config
from .example_module import example_function

def main():
    with open('conf.yaml', 'r') as f:
        load_config(config, f.read())
    
    example_function()

In the example_module

# example_module.py
from config import config

def example_function():
    print(config.field3)

Planned changes

  • XDG support
  • Move comments code into base file
  • Type checking
  • Tests in pipelines
  • Contribution guide
  • Scalars mapped to confclass
  • remove PyYAML

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts