Skip to main content

ClickSet

ClickSet is a thin wrapper around the click and confuse libraries, combining them both into a simple property-like interface for use with python classes.

from clickset import Setting
from clickset import ClickParams
from clickset import get_config
import confuse
import click

class MyClass:
    verbose = Setting(
        # confuse storage path
        'general.verbose',
        default = False,

        # click boolean option
        option = ClickParams(
            '--verbose/--quiet',
            help = 'Verbose or Quiet Output'
        )
    )

    enable = Setting(
        # confuse storage path
        'log.enable',

        # The subcommand this setting will be applied to
        command = 'log',

        # click boolean option
        option = ClickParams(
            '--enable/--disable',
            help = 'Enable or Disable logging subsystem'
        )
    )

    strdef = Setting(
        'strval',
        default = "DEADBEEF",
    )

    def my_func(self):
        # Get the value of a Setting
        print(f"verbose status: {self.verbose}")

        # Set the value of the property ... in memory only!
        self.verbose = True
        assert self.verbose == True

class OtherClass:
    # An existing `Setting` property may be copied from another object
    verbose = MyClass.verbose

@click.group
# Load all options set in classes
@Setting.options # <<< Only includes options where the `command` argument to `Setting` is not set.
def main(**kw):
    # Get the default global confuse configuration singleton
    config = get_config()
    foo = MyClass()
    print(f"verbose: {foo.verbose}")
    assert foo.verbose == kw['verbose']
    assert foo.verbose == config['general']['verbose'].get()

    # confuse/click values can also be obtained directly from classes
    # ... NOTE: The value here is read-only!
    assert MyClass.verbose.get() == kw['verbose']

    # confuse/click values can also be obtained without a class
    verbose = Setting(
        # confuse storage path
        'general.verbose',

        # click boolean option
        option = ClickParams(
            '--verbose/--quiet',
            help = 'Verbose or Quiet Output'
        )
    )
    assert verbose == MyClass.verbose.get()
    assert verbose == foo.verbose

    # Copied instances of a setting are always identical
    assert MyClass.verbose.get() == False
    assert foo.verbose == False
    assert MyClass.verbose.get() == OtherClass.verbose.get()
    foo.verbose = True
    assert foo.verbose == OtherClass.verbose.get()
    assert MyClass.verbose.get() == OtherClass.verbose.get()

    # Default values can be obtained from class properties
    assert MyClass.strdef.default == "DEADBEEF"

@main.command
# Load all options set in classes
@Setting.options('log') # <<< Only include options set via `Setting(..., command='log', ...)`
def log(**kw):
    assert len(kw) == 1
    assert 'enable' in kw
    assert kw['enable'] is True

main(['--verbose'])

Design Concepts

This library is built around the following design concept:

  • Define app configuration in the class where it is used
  • Link command line options to configuration file entries
  • Permit multiple configuration files covering different purposes
  • Provide a persistent application state storage mechanism
  • Provide a simple interface which covers common use scenarios
  • Provide as much access as possible to underlying libraries

These design concepts led me to utilizing two base libraries to provide functionality:

  • confuse: Provides configurable values to an application by providing multiple sources (memory, command line arguments, YAML files, etc.) in a priority based list.
  • click: Provides a command line interface which is easily extended with additional functionality.

While both of these libraries are very powerful tools in their own right, they both force their relevant settings into a central location. In order to keep all configuration settings in the location they are used, this library combines confuse and click into a single class called Setting. The resulting class has the following features:

  • All data is stored using confuse
  • Command line parameters provided by click are inserted into the confuse data store
  • Data is accessed in the same mechanism as a python property
  • Values can be overridden on a per-instance basis (same as setting a property)
  • click/confuse values can be obtained directly using Setting(...).get() in order to easily obtain configured values outside of class restrictions (see the example above)

While this design is highly flexible, there are noteworthy drawbacks which must be considered:

  • click parameter definitions and confuse data stores must be defined as global singletons.
    • Generally this is acceptable as both configuration files and command line interfaces have one instance per application.
    • Multiple singletons can be created for both confuse and click in order to provide design flexibility.
  • Command line options are always generated if the relevant class has been imported. This means that care must be taken with inactive code to ensure it is not imported by the main application.
    • This is generally a small risk if one is following good coding practices by importing only files which are used in a module.

Metadata

Release files for clickset 1.6.0

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

Source distribution (sdist)

Source distribution for clickset 1.6.0
File Size Uploaded Provenance Actions
clickset-1.6.0.tar.gz 8.4 kB Without provenance Details for clickset-1.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 18.3 kB

Release files / clickset-1.6.0.tar.gz

Download URL clickset-1.6.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8e41651c292b4909b61ec93dcbaa4873d1655ab1b24c3a4a932ef6f6948a09ab
BLAKE2b-256 checksum
How to use checksums
d4965dd07a9a89410251d834e339d5f1c95b4a5af025be010ca974dd96d901c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.14.2 Darwin/25.2.0

Release files / clickset-1.6.0-py3-none-any.whl

Download URL clickset-1.6.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9bc70d99fa1e9ca30bba13b0a3d75b0dff77306c420a32addb825cdb9548b42a
BLAKE2b-256 checksum
How to use checksums
c28fa8560bf2ddccd4ac2c382be0cfcb6855a32ec74d68b5cf6e8cba37460b63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.14.2 Darwin/25.2.0

Security for clickset 1.6.0

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