Skip to main content

confyml

Project to allow easy application of config to python methods and functions.

The package allows the user to provide keyword arguments to any decorated function/method. If keyword arguments are passed to the function/method directly in the code this will overwrite any configured behaviour. By having this, one can easily support configurability in applications without the need for code changes or unwieldy config classes that also require code change to alter.

install

Install like any other python package, from pypi

pip install confyml

usage

At the definition of classes, methods and functions, import confyml and apply the decorator to allow the function to become configurable.

# example_module.py
from confyml import confyml


config = confyml.get_config()


class ExampleClass:

    @config.apply
    def __init__(self, kwarg=None):
        self.kwarg = kwarg

    @config.apply
    def example_method(self, arg1, kwarg_2=None):
        return arg1, self.kwarg, kwarg_2


@config.apply()
def example_function(arg2, kwarg_3=None):
    return arg2, kwarg_3

Create a yaml file to hold the definition. Default mode for confyml is mcf: modules, classes and functions; where the yaml file has a structure like the one below.

# example.yaml
example_module:
  ExampleClass:
    kwarg: 'class_kwarg'
    example_method:
      kwarg_2: 'method_kwarg'
  example_function:
    kwarg_3: 'function_kwarg'

In the calling script, the application that uses the classes and functions, set the config file to follow.

# main.py
from confyml import confyml
import example_module

confyml.set_config('example.yaml')

e = example_module.ExampleClass()

print(e.example_method('arg1'))
print(example_module.example_function('arg2'))
$ python main.py
arg1 class_kwarg method_kwarg
arg2 function_kwarg

The use should be one config per application.

Keyword arguments provided to the function/method directly will overwrite the config file's behaviour.

# main.py
from confyml import confyml
import example_module

confyml.set_config('example.yaml')

e = example_module.ExampleClass(kwarg='direct_kwarg')

print(e.example_method('arg1'))
print(example_module.example_function('arg2', 'direct_func_kwarg'))
$ python main.py
arg1 direct_kwarg method_kwarg
arg2 direct_func_kwarg

modes

The config can also be provided with a mode argument,

# main.py
from confyml import confyml


confyml.set_config('<yaml_filepath>', mode='<mode>')

to set the level of the config. By default the mode is mcf, which supports a yaml structure of

module:
  Class:
    <defined_kwargs>
    method:
      <defined_kwargs>
  function:
    <defined_kwargs>

mode cf - classes and methods and/or functions

Class:
  <defined_kwargs>
  method:
    <defined_kwargs>
function:
  <defined_kwargs>

mode mf - modules and functions

module:
  function:
    <defined_kwargs>

and finally mode f - functions only

function:
  <defined_kwargs>

Use the mode that best suits your application.

Metadata

Release files for confyml 2.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for confyml 2.1.5
File Size Uploaded Provenance Actions
confyml-2.1.5.tar.gz 5.8 kB Without provenance Details for confyml-2.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for confyml 2.1.5
File Interpreter ABI Platform Actions
confyml-2.1.5-py3-none-any.whl Python 3 none any Details for confyml-2.1.5-py3-none-any.whl

Total release size: 12.8 kB

Release files / confyml-2.1.5.tar.gz

Download URL confyml-2.1.5.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e676ffacd3bfc10da2dd5b08a4b7c11b17446b7fdb38aefc01dfe24857c85cff
BLAKE2b-256 checksum
How to use checksums
c68e73bfa5a853185823e923a41cbc334ad8df0e89f51336611e0598c7719310
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release files / confyml-2.1.5-py3-none-any.whl

Download URL confyml-2.1.5-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11a64e8116d98df0576af424f173dd4b9184917d154ae28a3b491a9d6b424312
BLAKE2b-256 checksum
How to use checksums
b614ce1f6944b299213e8e6bb37124036e52598653057798996c750a7cf5d936
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Security for confyml 2.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page