Skip to main content

Automatically manage __all__ variable in Python packages.

Project description

Automatically manage the __all__ variable in Python packages.

pypi package build status downloads GitHub last commit GitHub GitHub stars

Overview

auto_all can be used for controlling what is made available for import from a package.

Installation

pip install auto-all

Usage

First, import the auto_all functions into your package.

from auto_all import start_all, end_all

If your package has external dependencies then these can be imported and the imported objects can be hidden. In this example we will import pathlib.Path and show that it doesn’t appear on the all list. We’re not actually going to use this import, it’s just for illustration.

from pathlib import Path

Now we can define some internal functions that we want to keep private. We can also do this using underscore prefixes, but auto_all gives us a little more control.

def a_private_function():
    print("This is a private function.")

Now we are ready to start defining public functions, so we use start_all(). We need to pass it the globals dict so that it can see what’s already defined.

start_all(globals())

Now we can define our public functions.

def a_public_function():
    print("This is a public function.")

Finally we use end_all() to finish defining public functions and create the __all__ variable.

end_all(globals())

When we look at the __all__ variable we can see only the public facing function is listed.

>>> print(__all__)
['a_public_function']

Putting this all together, your module should look something like this:

from auto_all import start_all, end_all

from pathlib import Path

def a_private_function():
    print("This is a private function.")

start_all(globals())

def a_public_function():
    print("This is a public function.")

end_all(globals())

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

auto-all-1.1.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

auto_all-1.1.0-py2.py3-none-any.whl (3.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file auto-all-1.1.0.tar.gz.

File metadata

  • Download URL: auto-all-1.1.0.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.1

File hashes

Hashes for auto-all-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ac6cfbf3c2470eab8e50072297e69d4bb6a4a4a25fb365d430eb97ebee9c20dd
MD5 738558d85e13a57d7a22ad336c97216f
BLAKE2b-256 44835b84d7b7de0f31d9af680d3a8b178e7923485f5f2570eeae29049c5691e6

See more details on using hashes here.

File details

Details for the file auto_all-1.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: auto_all-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.1

File hashes

Hashes for auto_all-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e2221dba2d49703b9dbc5129f7ab7476d6c3c032dff469e105cf2e741b32c3d4
MD5 e0528427e07acc739d61e91876530ed2
BLAKE2b-256 53ab8f97206030f2590cb7f3cf31c7cae225ecc762d9b329fff26223eefaa1c8

See more details on using hashes here.

Supported by

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