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: IUnboundFactoryRegistry, env: Optional[Hashable] = None)

Dependency injector main class.

Parameters
  • 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.

Parameters
  • key – Searched key

  • env – Searched environment

exception OutOfScopeError(key, scope, required_scope)

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

Parameters
  • key – Searched key

  • scope – Injector’s own scope

  • required_scope – Required scope

close() Optional[Awaitable[None]]

See pydio.base.IInjector.close().

property env: Optional[Hashable]

Environment assigned to this injector.

inject(key)

See IInjector.inject.

is_closed() bool

Return True if this injector was closed or False otherwise.

scoped(scope: Hashable, env: Optional[Hashable] = None) 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.

Parameters
  • key – Registered key

  • env – Registered environment

attach(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().

has_awaitables()

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()

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

Register user factory function.

Parameters
  • 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)

Parameters
  • key – The key to be wrapped

  • kwargs – Additional parameters to be bound with given key

property key

Wrapped key.

property kwargs: dict

Dict with parameters given in constructor.