Skip to main content

The janitor

Project description

Scruffy. The Janitor.

Scruffy is a framework for taking care of a bunch of boilerplate in Python apps. It handles the loading of configuration files, the loading and management of plugins, and the management of other filesystem resources such as temporary files and directories, log files, etc.

A typical use case for Scruffy is a command-line Python tool with some or all of the following requirements:

  • Read a set of configuration defaults

  • Read a local configuration file and apply it on top of the defaults

  • Allow overriding some configuration options with command line flags or at runtime

  • Load a core set of Python-based plugins

  • Load a set of user-defined Python-based plugins

  • Generate log files whose name, location and other logging settings are based on configuration

  • Store application state between runs in a file or database

Scruffy is used by Voltron and Calculon


A standard python setup script is included.

$ python install

This will install the Scruffy package wherever that happens on your system.

Alternately, Scruffy can be installed with pip from PyPi (where it’s called scruffington, because I didn’t check for a conflict before I named it).

$ pip install scruffington


Full documentation is hosted at readthedocs

Quick start


Load a user config file, and apply it on top of a set of defaults loaded from inside the Python package we’re currently running from.


some_property:  1
other_property: a thing

from scruffy import ConfigFile

c = ConfigFile('thingy.yaml', load=True,
    defaults=File('defaults.yaml', parent=PackageDirectory())

print("c.some_property == {c.some_property}".format(c=c))
print("c.other_property == {c.other_property}".format(c=c))

Run it:

$ python
c.some_property == 1
c.other_property == a thing


Load some plugins.


from scruffy import Plugin

class ExamplePlugin(Plugin):
    def do_a_thing(self):
        print('{}.{} is doing a thing'.format(__name__, self.__class__.__name__))

from scruffy import PluginDirectory, PluginRegistry

pd = PluginDirectory('~/.thingy/plugins')

for p in PluginRegistry.plugins:
    print("Initialising plugin {}".format(p))

Run it:

$ python
Initialising plugin <class 'example.ExamplePlugin'>
example.ExamplePlugin is doing a thing


Scruffy’s LogFile class will do some configuration of Python’s logging module.

import logging
from scruffy import LogFile

log = logging.getLogger('main')
LogFile('/tmp/thingy.log', logger='main').configure()'Hello from')


Hello from


Scruffy’s Environment class ties all the other stuff together. The other classes can be instantiated as named children of an Environment, which will load any Config objects, apply the configs to the other objects, and then prepare the other objects.


log_dir:    /tmp/logs
log_file:   thingy.log

from scruffy import *

e = Environment(
    main_dir=Directory('~/.thingy', create=True,
        config=ConfigFile('config', defaults=File('defaults.yaml', parent=PackageDirectory())),
    log_dir=Directory('{config:log_dir}', create=True
        LogFile('{config:log_file}', logger='main')
    pkg_plugins=PluginDirectory('plugins', parent=PackageDirectory())


See LICENSE file. If you use this and don’t hate it, buy me a beer at a conference some time.


Props to richo. Flat duck pride.

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

scruffington- (11.8 kB view hashes)

Uploaded source

Built Distribution

scruffington- (14.2 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page