Skip to main content
https://img.shields.io/travis/snare/scruffy.svg https://img.shields.io/pypi/format/scruffington.svg https://readthedocs.org/projects/scruffy/badge/?version=latest

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

Installation

A standard python setup script is included.

$ python setup.py 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

Documentation

Full documentation is hosted at readthedocs

Quick start

Config

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.

thingy.yaml:

some_property:  1
other_property: a thing

thingy.py:

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 thingy.py
c.some_property == 1
c.other_property == a thing

Plugins

Load some plugins.

~/.thingy/plugins/example.py:

from scruffy import Plugin

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

thingy.py:

from scruffy import PluginDirectory, PluginRegistry

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

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

Run it:

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

Logging

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

log.py:

import logging
from scruffy import LogFile

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

log.info('Hello from log.py')

/tmp/thingy.log:

Hello from log.py

Environment

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.

~/.thingy/config:

log_dir:    /tmp/logs
log_file:   thingy.log

env.py:

from scruffy import *

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

License

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

Credits

Props to richo. Flat duck pride.

Release files for scruffington 0.3.10

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

Source distribution (sdist)

Source distribution for scruffington 0.3.10
File Size Uploaded
scruffington-0.3.10.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scruffington 0.3.10
File Interpreter ABI Platform
scruffington-0.3.10-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 26.8 kB

Release files / scruffington-0.3.10.tar.gz

Download URL scruffington-0.3.10.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
84e644ec7c84902ca3b37a7eb89e59ee4b0c053f226d51bb38158c2d06086a72
BLAKE2b-256 checksum
How to use checksums
8d061cbd829c20daf7debbf057b6eed3029196e1318dc455f2e4c26a2b9e3cb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / scruffington-0.3.10-py2.py3-none-any.whl

Download URL scruffington-0.3.10-py2.py3-none-any.whl
Size 14.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8cb7f0fc7b30bf3de8ed5c265f7571ca60ac15dbbeabc31beb2d6e36fb261d66
BLAKE2b-256 checksum
How to use checksums
7f710fbdeaa243b6c6ff27ef6c868ce3e6a25e5059c50b1e0823344f733f6fc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.3.10 This release

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

2 release files

0.3.2

1 release file

0.3.1

1 release file

0.3

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