Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Dirty loader for python 3

Project Description

dirty-loader

Easy to use loader library.

Changelog

Version 0.2.2

  • Simplified code.
  • Added BaseFactory methods to load items from list or dictionaries.

Version 0.2.1

  • Three types of instance definition allowed: string, structured and structure simplified.

Version 0.2.0

  • Custom factories for classes.
  • Default factories for logging package.

Version 0.1.0

  • Some refactors.
  • New function import_class.

Instalation

$ pip install dirty-loader

Main loaders

Loader

With Loader you could register sorted python modules. When you ask for a class it will try to load it for each module until it find one.

Example:

from dirty_loader import Loader

loader = Loader()
loader.register_module('tests.fake.namespace1')
loader.register_module('tests.fake.namespace2')
loader.register_module('tests.fake.namespace3')

klass = loader.load_class('FakeClass1')

from tests.fake.namespace1 import FakeClass1
assert klass == FakeClass1

# klass is tests.fake.namespace1.FakeClass1 because it exists in first module registered.
# Also, you could get an instance of class using factory
obj = loader.factory('FakeClass1', var1='a', var2=2)

# You could load classes from packages inside modules registered
klass = loader.load_class('subnamespace.FakeClass1')
from tests.fake.namespace3.subnamespace import FakeClass1 as SubFakeClass1
assert klass == SubFakeClass1
# klass is tests.fake.namespace3.subnamespace.FakeClass1 because it exists in first module registered.

LoaderReversed

It works in same way of Loader but it revers the sort when try to load a class.

Example:

from dirty_loader import LoaderReversed

loader = LoaderReversed()
loader.register_module('tests.fake.namespace1')
loader.register_module('tests.fake.namespace2')

klass = loader.load_class('FakeClass1')

from tests.fake.namespace2 import FakeClass1
assert klass == FakeClass1

# klass is tests.fake.namespace2.FakeClass1 because it exists in last module registered.

LoaderNamespace

With LoaderNamespace you could register sorted namespaces. When you ask for a class it will try to load it for each namespace until it find one. Each namespace has a python module associated. You could use the regular Loader way to load a class or you could specify the namespace you would like to use.

Example:

from dirty_loader import LoaderNamespace

loader = LoaderNamespace()
loader.register_namespace('fake1', 'tests.fake.namespace1')
loader.register_namespace('fake2', 'tests.fake.namespace2')

from tests.fake.namespace1 import FakeClass1, FakeClass2, FakeClass3

klass = loader.load_class('FakeClass1')

from tests.fake.namespace1 import FakeClass1
assert klass == FakeClass1
# klass is tests.fake.namespace1.FakeClass1 because it exists in last module registered.

# Also, you could get a class from specific namespace

klass = loader.load_class('FakeClass1', namespace='fake2)

from tests.fake.namespace2 import FakeClass1
assert klass == FakeClass1
# klass is tests.fake.namespace2.FakeClass1 because you specified it.

# Namespace could be specified in string class, too
klass = loader.load_class('fake2:FakeClass1')

assert klass == FakeClass1
# klass is tests.fake.namespace2.FakeClass1 because you specified it.

LoaderNamespaceReversed

It works in same way of LoaderNamespace but it revers the sort when try to load a class.

LoaderCached

A version of Loader with cache.

LoaderReversedCached

A version of LoaderReversed with cache.

LoaderNamespaceCached

A version of LoaderNamespace with cache.

LoaderNamespaceReversedCached

A version of LoaderNamespaceReversed with cache.

Release History

Release History

This version
History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

History Node

0.1.0

History Node

0.0.2

History Node

0.0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
dirty-loader-0.2.2.tar.gz (5.7 kB) Copy SHA256 Checksum SHA256 Source Oct 10, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting