<h1 align="center">python-exports</h1>
<p align="center">
The DRY alternative to </code>__all__</code>
</p>
<p align="center">
<a href="https://pypi.org/project/python-exports/">
<img
alt="exports - PyPI"
src="https://img.shields.io/pypi/v/python-exports?style=flat"
/>
</a>
<a href="https://github.com/jorenham/exports">
<img
alt="exports - Python Versions"
src="https://img.shields.io/pypi/pyversions/python-exports?style=flat"
/>
</a>
<a href="https://github.com/jorenham/exports">
<img
alt="exports - license"
src="https://img.shields.io/github/license/jorenham/exports?style=flat"
/>
</a>
</p>
<p align="center">
<a href="https://github.com/jorenham/exports/actions?query=workflow%3ACI">
<img
alt="exports - CI"
src="https://github.com/jorenham/exports/workflows/CI/badge.svg"
/>
</a>
<a href="https://github.com/pre-commit/pre-commit">
<img
alt="exports - pre-commit"
src="https://img.shields.io/badge/pre--commit-enabled-orange?logo=pre-commit"
/>
</a>
<a href="https://github.com/KotlinIsland/basedmypy">
<img
alt="exports - basedmypy"
src="https://img.shields.io/badge/basedmypy-checked-fd9002"
/>
</a>
<a href="https://detachhead.github.io/basedpyright">
<img
alt="exports - basedpyright"
src="https://img.shields.io/badge/basedpyright-checked-42b983"
/>
</a>
<a href="https://github.com/astral-sh/ruff">
<img
alt="exports - ruff"
src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json"
/>
</a>
</p>
-----
## Installation
To install the `exports` package, you can use
[`python-exports` on PyPI](https://pypi.org/project/python-exports/):
```bash
pip install python-exports
```
## Usage
```pycon
>>> from exports import export
```
Now you can use it to add to `__all__` as
- function decorator
```pycon
>>> @export
... def spam():
... ...
```
- class decorator:
```pycon
>>> @export
... class Ham:
... ...
```
- by name:
```pycon
>>> 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:
```pycon
>>> def eggs():
... ...
>>> fake_eggs = eggs
```
If we want to export fake_eggs, then this **will not work**:
```pycon
>>> export(fake_eggs) # BAD: this will add `'eggs'` to `__all__`
```
In such cases, use the name instead:
```pycon
>>> 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.
Raw data
{
"_id": null,
"home_page": "https://github.com/jorenham/exports",
"name": "python-exports",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Joren Hammudoglu",
"author_email": "jhammudoglu@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f6/83/58acae682edb28a9a97d2c67f46e9650608df044c5d7fd8e05c71da58ced/python_exports-1.2.0.tar.gz",
"platform": null,
"description": "<h1 align=\"center\">python-exports</h1>\n\n<p align=\"center\">\n The DRY alternative to </code>__all__</code>\n</p>\n\n<p align=\"center\">\n <a href=\"https://pypi.org/project/python-exports/\">\n <img\n alt=\"exports - PyPI\"\n src=\"https://img.shields.io/pypi/v/python-exports?style=flat\"\n />\n </a>\n <a href=\"https://github.com/jorenham/exports\">\n <img\n alt=\"exports - Python Versions\"\n src=\"https://img.shields.io/pypi/pyversions/python-exports?style=flat\"\n />\n </a>\n <a href=\"https://github.com/jorenham/exports\">\n <img\n alt=\"exports - license\"\n src=\"https://img.shields.io/github/license/jorenham/exports?style=flat\"\n />\n </a>\n</p>\n<p align=\"center\">\n <a href=\"https://github.com/jorenham/exports/actions?query=workflow%3ACI\">\n <img\n alt=\"exports - CI\"\n src=\"https://github.com/jorenham/exports/workflows/CI/badge.svg\"\n />\n </a>\n <a href=\"https://github.com/pre-commit/pre-commit\">\n <img\n alt=\"exports - pre-commit\"\n src=\"https://img.shields.io/badge/pre--commit-enabled-orange?logo=pre-commit\"\n />\n </a>\n <a href=\"https://github.com/KotlinIsland/basedmypy\">\n <img\n alt=\"exports - basedmypy\"\n src=\"https://img.shields.io/badge/basedmypy-checked-fd9002\"\n />\n </a>\n <a href=\"https://detachhead.github.io/basedpyright\">\n <img\n alt=\"exports - basedpyright\"\n src=\"https://img.shields.io/badge/basedpyright-checked-42b983\"\n />\n </a>\n <a href=\"https://github.com/astral-sh/ruff\">\n <img\n alt=\"exports - ruff\"\n src=\"https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json\"\n />\n </a>\n</p>\n\n-----\n\n## Installation\n\nTo install the `exports` package, you can use\n[`python-exports` on PyPI](https://pypi.org/project/python-exports/):\n\n```bash\npip install python-exports\n```\n\n## Usage\n\n```pycon\n>>> from exports import export\n```\n\nNow you can use it to add to `__all__` as\n\n- function decorator\n\n ```pycon\n >>> @export\n ... def spam():\n ... ...\n ```\n\n- class decorator:\n\n ```pycon\n >>> @export\n ... class Ham:\n ... ...\n ```\n\n- by name:\n\n ```pycon\n >>> from functools import reduce as fold\n >>> export('fold')\n ```\n\n## Behaviour\n\nIf the module has no `__all__`, it is created.\nOtherwise, `__all__` is converted to a list, and the export is appended.\n\n## Caveats\n\nExporting a function or class directly relies on the `__name__` attribute,\nso consider the following example:\n\n```pycon\n>>> def eggs():\n... ...\n>>> fake_eggs = eggs\n```\n\nIf we want to export fake_eggs, then this **will not work**:\n\n```pycon\n>>> export(fake_eggs) # BAD: this will add `'eggs'` to `__all__`\n```\n\nIn such cases, use the name instead:\n\n```pycon\n>>> export('fake_eggs') # GOOD\n```\n\nYou'll be safe if you either\n\n- decorate a function or a class directly with `@export`,\n- pass the name string when using plain `export('...')` calls.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "@export decorator that adds a function or class to __all__",
"version": "1.2.0",
"project_urls": {
"Bug Tracker": "https://github.com/jorenham/exports/issues",
"Changelog": "https://github.com/jorenham/exports/releases",
"Documentation": "https://github.com/jorenham/exports/blob/master/README.md",
"Homepage": "https://github.com/jorenham/exports",
"Repository": "https://github.com/jorenham/exports"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bec9e3f578b6c4994829f71c2aa910d981c57a553b309b5fa5fc2c1ad7df5733",
"md5": "971bc38dae5ac9167eab8a9a038b35bc",
"sha256": "cb599fb29fbe667914ba354f6692afb3f0bedfbcf0cf3ac75e55343a86247c43"
},
"downloads": -1,
"filename": "python_exports-1.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "971bc38dae5ac9167eab8a9a038b35bc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 4350,
"upload_time": "2024-08-19T20:44:12",
"upload_time_iso_8601": "2024-08-19T20:44:12.094378Z",
"url": "https://files.pythonhosted.org/packages/be/c9/e3f578b6c4994829f71c2aa910d981c57a553b309b5fa5fc2c1ad7df5733/python_exports-1.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f68358acae682edb28a9a97d2c67f46e9650608df044c5d7fd8e05c71da58ced",
"md5": "8413f7d6f83065d08a791d6a02415904",
"sha256": "f5ef300c20f4dfcaf5b324f1449550d4ea0d1c4048fd390e6f00f6bd69b977ad"
},
"downloads": -1,
"filename": "python_exports-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "8413f7d6f83065d08a791d6a02415904",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 4767,
"upload_time": "2024-08-19T20:44:13",
"upload_time_iso_8601": "2024-08-19T20:44:13.227208Z",
"url": "https://files.pythonhosted.org/packages/f6/83/58acae682edb28a9a97d2c67f46e9650608df044c5d7fd8e05c71da58ced/python_exports-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-19 20:44:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jorenham",
"github_project": "exports",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "python-exports"
}