Skip to main content

Handy import wrappers to simplify optional dependency management

Project description

PyPI version PyPI pyversions Coverage Status Build Status

Import Wrappers

A simple set of utilities to make working with various import patterns easy.

Installation

pip install import-wrappers

Optional Dependencies

The original motivation for this library was the repetitive utilities I found myself authoring to hack around supporting optional dependencies in other projects. Optional dependencies are a common pattern where the core of a library does not depend on a dependency but some functionality may require it. Most users may never interact with the code that requires the optional dependency but without proper handling will still be required to install them and by extension inherit the overhead of managing dependency versions and conflicts.

Usage

Wrapping Optional Dependencies

Typical import pattern - this fails on import whether or not the dependency is used

from optional_dependency import SomeUnusedClass


def some_function_that_isnt_needed(*args, **kwargs):
    return SomeUnusedClass().some_method(*args, **kwargs)

Same functionality using import wrappers - only raise an error on USE, not import

from import_wrappers.optional_dependencies import OptionalDependencyWrapper

SomeUnusedClass = OptionalDependencyWrapper('optional_dependency', 'SomeUnusedClass')

def some_function_that_isnt_needed(*args, **kwargs):
    return SomeUnusedClass().some_method(*args, **kwargs)

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

import-wrappers-0.0.2.tar.gz (5.3 kB view hashes)

Uploaded Source

Built Distribution

import_wrappers-0.0.2-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page