Skip to main content

travis-master coverall-master Documentation Status

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

Documentation

http://dirty-loader.readthedocs.io

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.

Metadata

Release files for dirty-loader 0.2.2

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

Source distribution (sdist)

Source distribution for dirty-loader 0.2.2
File Size Uploaded Provenance
dirty-loader-0.2.2.tar.gz 5.7 kB Without provenance Details

Release files / dirty-loader-0.2.2.tar.gz

Download URL dirty-loader-0.2.2.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
088bbea7e3f8e9046b3ef3917fd71cc250f0d87c23040418fa5c384ee79d0753
BLAKE2b-256 checksum
How to use checksums
49caa4d0b9f501119d564c2cf44051fd10564507f7d35663931cdb7bae4d3e30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for dirty-loader 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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