Skip to content

Handy import wrappers to simplify optional dependency management

License

Notifications You must be signed in to change notification settings

eyadgaran/import-wrappers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

Handy import wrappers to simplify optional dependency management

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages