Skip to main content

Dependency inversion for python, the easy way

Nutshell

Deedee provides an API which enables the developer to use late binding for default values in function definition.

Example:

import deedee

class Database:
    def select(self, query):
        print("select", query)


@deedee.resolve
def handler(param_a, param_b, database=deedee.context.database):
    print(param_a, param_b)  # param_a and param_b are unchanged
    print(database) # this will print a database instance
    database.select("select * from table order by id")  # this call will be successful


def main():
    # register the default value (which will be used when calling handler)
    deedee.context.register("database", Database())

    # call the handler, the 3rd parameter will be the previously registered value
    handler("param_1", "param_2")


if __name__ == '__main__':
    main()

In python the binding of the default value happens at the function defintion, so it is not possible to set the default parameter later on, the expression after the ‘=’ sign gets evaluated at the function definition.

With deedee this changes, so you can specify a reference instead, and later on, specify the value for that reference.

When the function is called later on, the decorator deedee.resolve will resolve the reference of the default value.

This can be used to implement dependency injection and dependency inversion patterns without using any boilerplate classes or functions.

Features

  • Lazy evaluation of the default parameters

  • Default value can be overriden by specifying it during the call (same behaviour as ‘normal’ default values)

  • It can be traced which function references to a given default parameter (soon)

  • It can be checked that all references can be resolved in the future, so it can be ensured that there will be no error with resolving during function calls

  • Context objects can be implemented by the user (it is not required to use deedee.context)

  • Annotations can be use freely, the library doesn’t use or change them

  • Nearly straightforward implementation, good test coverage

Name

According to urban dictionary, deedee is:

A person who is always there when you need them. A strong survivor who can make it through anything.

In deedee the values you are registering to a context behave like this – they are always there when you need them.

Release files for deedee 0.1

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

Source distribution (sdist)

Source distribution for deedee 0.1
File Size Uploaded
deedee-0.1.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for deedee 0.1
File Interpreter ABI Platform
deedee-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / deedee-0.1.tar.gz

Download URL deedee-0.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
25f1acaa45160402c0c8fcb45f1d88ae1a85526500ae997ba2eb5b24714a934b
BLAKE2b-256 checksum
How to use checksums
c571be324239e2347f679a6686cbf0f45018ccb46f68b3eb7e7386255dc2de35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / deedee-0.1-py3-none-any.whl

Download URL deedee-0.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ded2b86b85623efecbac66ea3caa621349afc4305b0ca076e3d9144d92a8a33
BLAKE2b-256 checksum
How to use checksums
0b768b9b9ff9d814251c26ab8bf76e8bca224c510a7aa8c13ab70d2c70c7aec3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

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