Skip to main content
require is a framework for module definitions.


== Overview ==
It allows to publish dependencies. A function can be decorated to require
dependencies by its name.


== Usage ==
A requirement must be exported using the @export(...) decorator. The decorated
function will be called on the first time it is required and the result is
cached for later use. It's also possible to decorated a class or anything else
which is callable.

To require a dependency the @require(...) decorator can be used. This decorator
expects a mapping between parameter names and dependencies. If the decorated
function is called, the requirements are resolved and the returned values are
passed to the decorated function. The parameter name used to pass the resolved
requirements are the same names as used to specify the requirements.

It is possible to extend and manipulate an export using the @extend(...)
decorator. After calling the exported function, the return value is passed to
all defined extends for this dependency. The extend function can manipulate the
object or replace it with another one.


== Example ==
file: example/foo.py

from require import export

@export()
def my_export():
# This function will be called on first requirement
return 'exported object'


file: example/bar.py

from require import extend

@extend('example.foo:my_export')
def extend_my_export(my_export):
# The passed parameter is the result of the required function
# If the extend function returns a new value, the export is replaced by it
return 'extended and ' + my_export


file: example/baz.py

from require import require

@require(my_fancy_export = 'example.foo:my_export')
def my_user(my_fancy_export):
# Parameter 'my_fancy_export' must match the name in the decorator
# This will print 'extended and exported object'
print(my_fancy_export)

Metadata

Release files for require 0.1.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 require 0.1.1
File Size Uploaded Provenance Actions
require-0.1.1.tar.gz 4.3 kB Without provenance Details for require-0.1.1.tar.gz

Release files / require-0.1.1.tar.gz

Download URL require-0.1.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a6ad4d5b20d7978e17d98580be546d13fc55c6e79972405d05915cc7edc68d40
BLAKE2b-256 checksum
How to use checksums
ef77292381a3dd42abffee3e8270531578d7ab862ee1191787f7528cea272ca0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for require 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file No provenance

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