Skip to main content

Add readability and self-documentation to Python code

Project description

readables-py

Enhance code readability and self-documentation in our Python code


Distributed Lock

[!NOTE] Check out the dedicated documentation.


Environment Variable Manager and Exporter

Declare and retrieve variables

Here is how you can declare and retrieve variables.

# file: your_app/constants.py
from readables.env import required_env, optional_env, flag

ALPHA = required_env('ALPHA', help='Alpha variable')
BETA = optional_env('BETA', 'default_value', help='Beta variable')
CHARLIE = flag('CHARLIE', help='Charlie flag')

[!TIP] When required_env is used, if the variable is not set, it will raise an exception.

Export variables

We have provided two exporters: the env file exporter and the MarkDown exporter. If you are working on the code that the required environment variables have not been set, you will need to set READABLES_ENV_ALLOW_UNSET_REQUIRED to true before using an exporter to suppress the error.

In this example, we use the env file exporter to generate the content of the distributed env file using the content above.

# file: scripts/gen_dist_env.py
from os import environ

environ['READABLES_ENV_ALLOW_UNSET_REQUIRED'] = 'true'

# noinspection PyUnresolvedReferences
from your_app import constants
from readables.env import manager, EnvFileExporter

output = EnvFileExporter.export(manager.variables)

[!NOTE] An exporter does not know how to scan the code. So, you need to find the way to ensure that the manager knows the declared variables. In this example, it imports any references to the "static" variables.

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

readables_py-0.2.3.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

readables_py-0.2.3-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file readables_py-0.2.3.tar.gz.

File metadata

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

File hashes

Hashes for readables_py-0.2.3.tar.gz
Algorithm Hash digest
SHA256 78f007b1f2944b68914b5e38a1f035e7b0d034d0223ce652f3394b3866d675ea
MD5 47e72431db4338bb9d4311ae610b107a
BLAKE2b-256 5ebd5e83feacac28335f641982a8d97d15dd1e5f215393c5910c2d503a35ecad

See more details on using hashes here.

Provenance

The following attestation bundles were made for readables_py-0.2.3.tar.gz:

Publisher: package-release.yml on shiroyuki/readables-py

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

File details

Details for the file readables_py-0.2.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for readables_py-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eeb101574f9e35e41559a73a9d8945fff9322cdb23693b859d7040337ae28a8a
MD5 4e9a6240d8c57ea7d9b1f1decb062baa
BLAKE2b-256 db959d9b5f9095632fbfedf4d6ebac2c6cc6ead6e9ec50e356608299c4fba181

See more details on using hashes here.

Provenance

The following attestation bundles were made for readables_py-0.2.3-py3-none-any.whl:

Publisher: package-release.yml on shiroyuki/readables-py

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