pydio.api - All core classes in one place

An all-in-one module for making imports easier.

You can use this in your code to create one-line imports. For example, instead of adding multiple PyDio imports to your application, you can do this instead:

from pydio.api import Injector, Provider
class pydio.api.Injector(provider: pydio.base.IUnboundFactoryRegistry, env: Optional[Hashable] = None)

Dependency injector main class.

  • provider – Unbound factory provider to work on

  • env

    Name of the environment this injector will use when making queries to IUnboundFactoryRegistry object given via provider.

    This can be obtained f.e. from environment variable. Once injector is created you will not be able to change this.

    See IUnboundFactoryRegistry.get() for more details.

exception AlreadyClosedError(**kwargs)

Raised when operation on a closed injector was performed.

exception NoProviderFoundError(key, env)

Raised when there was no matching provider found for given key.

  • key – Searched key

  • env – Searched environment

property env
property key
exception OutOfScopeError(key, scope, required_scope)

Raised when there was attempt to create object that was registered for different scope.

  • key – Searched key

  • scope – Injector’s own scope

  • required_scope – Required scope

property key
property required_scope
property scope

See pydio.base.IInjector.close().

property env

Environment assigned to this injector.


See IInjector.inject.


Return True if this injector was closed or False otherwise.

scoped(scope: Hashable, env: Optional[Hashable] = None)pydio.base.IInjector

See pydio.base.IInjector.scoped().

class pydio.api.Provider

Used to record user-defined object factories or instances and bind them with particular key, that can later be used by IInjector.inject().

exception DoubleRegistrationError(key, env)

Raised when same (key, env) tuple was used twice during registration.

  • key – Registered key

  • env – Registered environment

property env
property key
attach(provider: pydio.provider.Provider)

Attach given provider to this provider.

This effectively extends current provider with object factories registered to the other one.

Use this if you need to split your providers across multiple modules.

get(key, env=None)

See IUnboundFactoryRegistry.get().


See IUnboundFactoryRegistry.has_awaitables().

provides(key, scope=None, env=None)

Same as register_func(), but to be used as a decorator.

Here’s an example:

from pydio.api import Provider

provider = Provider()

def make_spam():
    return 'give me more spam'
register_func(key, func, scope=None, env=None)

Register user factory function.

  • key

    Key to be used for func.

    See IInjector.inject() for more info.

  • func

    User-defined function to be registered.

    This can be normal function, coroutine, generator or async denerator.

  • scope – Optional scope to be assigned.

  • env – Optional environment to be assigned

register_instance(key, value, scope=None, env=None)

Same as register_func(), but for registration of constant objects.

If your application has some global configuration data you want to inject using PyDio - that’s the method you should use.

class pydio.api.Variant(key: Hashable, **kwargs: Hashable)

A special form of key that can have user-defined parameters attached.

This class can be used if you need to use same key twice, but return different objects depending on additional parameters given (which can be accessed by object factory)

  • key – The key to be wrapped

  • kwargs – Additional parameters to be bound with given key

property key

Wrapped key.

property kwargs

Dict with parameters given in constructor.