Skip to main content

@export decorator that adds a function or class to __all__

Project description

@exports

The DRY alternative to __all__

GitHub License PyPI Version Python Versions
Typing basedpyright mypy pyrefly ruff ruff


Installation

To install the exports package, you can use python-exports on PyPI:

pip install python-exports

Usage

>>> from exports import export

Now you can use it to add to __all__ as

  • function decorator

    >>> @export
    ... def spam():
    ...     ...
    
  • class decorator:

    >>> @export
    ... class Ham:
    ...     ...
    
  • by name:

    >>> from functools import reduce as fold
    >>> export('fold')
    

Behaviour

If the module has no __all__, it is created. Otherwise, __all__ is converted to a list, and the export is appended.

Caveats

Exporting a function or class directly relies on the __name__ attribute, so consider the following example:

>>> def eggs():
...     ...
>>> fake_eggs = eggs

If we want to export fake_eggs, then this will not work:

>>> export(fake_eggs)  # BAD: this will add `'eggs'` to `__all__`

In such cases, use the name instead:

>>> export('fake_eggs')  # GOOD

You'll be safe if you either

  • decorate a function or a class directly with @export,
  • pass the name string when using plain export('...') calls.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_exports-1.3.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_exports-1.3.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file python_exports-1.3.0.tar.gz.

File metadata

  • Download URL: python_exports-1.3.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_exports-1.3.0.tar.gz
Algorithm Hash digest
SHA256 124303d1f643b4e2c3bcbf5e1140f00da85b52c60bd11ce57f0104ae1dd0cad2
MD5 93e1efa7266193eb4d58c61c333b03b4
BLAKE2b-256 4d13e0c77bb1d951e59af8a455c7280642c7e48a93febafb56b17f0931ef4176

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_exports-1.3.0.tar.gz:

Publisher: publish-pypi.yml on jorenham/exports

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_exports-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: python_exports-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_exports-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd1baafa2ced944a0df3baa79b78cb3e416f8dd9a10c329516de156d80ff3dc8
MD5 36601abe4786c5bacab5d3c5b3172b89
BLAKE2b-256 1a534f96521f0402fce3a8a3642a3d4868c7320bfd9a2741dfbaf4c2b8cce641

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_exports-1.3.0-py3-none-any.whl:

Publisher: publish-pypi.yml on jorenham/exports

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page