Skip to main content

Dismantle

Dismantle is a module created for Python programs to provide the ability to provide additional functionality using packages listed within local or remote indices and installed during runtime.

Dismantle does this by checking a package index and using that index to manage package versions. Packages then contain plugins (using decorators) and extensions (using a custom module loader) to add the additional functionality to the application.

Installing Dismantle

Dismantle is available on PyPI:

$ python -m pip install dismantle

NOTE: *Dismantle officially supports Python from 3.7 up

Supported Features & Best–Practices

Dismantle provides the flexibility within applications allowing developers to build rich ecosystems around core applications. It does this by providing the following:

Index Management

Index files are used to provide list of available packages and provide information on packages and the versions of said packages available.

  • support for multiple index files that cascade
  • easy to create custom index handlers providing additional ways to define package indices
  • local index file support using json built in
  • url based index file support using json built in
  • etag based caching for url based index

Packaging

Packages listed in index files provide the ability to bundle features and act as a transport mechanism for additional functionality while providing security.

  • easy to create custom package handlers providing additional ways to define package sources
  • easy to create custom package formats compression types and structures
  • support for zip, tar.gz, tgz, and local directories as package formats built in
  • support for local and url based (http/https) package handlers built in
  • hash validation for packages with the ability to verify package integrity

Extensions

Extensions contained within packages provide a way to dynamically load modules at runtime for Python modules as needed. Packages can replace or extend application functionality at runtime by replacing or adding modules in Pythons global modules manager.

  • Categorized extension groups to filter extension types (eg. loggers, parsers, ...)
  • Support for init or .py based module loading.
  • Extension activation and deactivation management.
  • Module name collision avoidance
  • Hierarchical module naming

Plugins

Plugins contained within packages provide a way to intercept function parameters and return values in order to manipulate data on the fly. Plugins can be used for data validation, manipilation, or to provide additional logging or auditing functionality.

  • Decorator based plugins with pre and post value interceptions and/or modification
  • Multiple plugins per function with ability to set execution order
  • Activation management

Example implementations

Plugin

"""Simple plugin example"""
from dismantle import plugin


class Chat():
    @plugin.register('chat.message')
    def show(self, message):
        print(message)


@plugin.plugin('chat.message', order=-1)
def make_uppercase(message):
    return message.upper()

Extension

"""Full example using all aspects."""
from dismantle.extension import Extensions, IExtension
from dismantle.index import JsonFileIndexHandler
from dismantle.package import LocalPackageHandler


class ColorExtension(IExtension):
    _category = 'color'

    def color(self) -> None:
        ...


class GreenColorExtension(ColorExtension):
    _name = 'green'

    def color(self) -> None:
        print(f'color is {self._name}')


packages = {}
index = JsonFileIndexHandler('index.json')
for pkg_meta in index:
    meta = index[pkg_meta]
    package = LocalPackageHandler(meta['name'], 'foo/path')
    package._meta = {**package._meta, **meta}
    package.install()
    packages[package.name] = package
extensions = Extensions([ColorExtension], packages, 'ext_')
assert extensions.types == ['color']
assert list(extensions.category('color').keys()) == [
    '@scope-one/package-one.extension.green.GreenColorExtension',
    '@scope-one/package-two.extension.red.RedColorExtension',
    '@scope-one/package-three.extension.blue.BlueColorExtension',
]
assert list(extensions.extensions.keys()) == ['color']
assert list(extensions.imports.keys()) == [
    '@scope-one/package-one.extension.green',
    '@scope-one/package-two.extension.red',
    '@scope-one/package-three.extension.blue'
]

Release files for dismantle 1.1.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 dismantle 1.1.0
File Size Uploaded
dismantle-1.1.0.tar.gz 31.2 kB Details

Built distribution (wheel)

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

Total release size: 48.7 kB

Release files / dismantle-1.1.0.tar.gz

Download URL dismantle-1.1.0.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
046cc428ff8b4b6474e7a49c9ffccfeea85c853c1f1a8ab8d0cc14831603ec63
BLAKE2b-256 checksum
How to use checksums
eff8b7a4b7eb582d1468fdd6d81b1aa029e533d5c070b8f9ac049e0728d72483
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.4.6 CPython/3.11.2

Release files / dismantle-1.1.0-py3-none-any.whl

Download URL dismantle-1.1.0-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36d1149e87c6638d0807cdca08aee28dd572ba7f06c9a5d95f456251a387cde9
BLAKE2b-256 checksum
How to use checksums
489de5258f0294d5d505b8de4cfa2e68d7775d79432ca13b8412cf7b27df989f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.4.6 CPython/3.11.2

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.11.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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