Skip to main content

Optional Dependency Hint

This package gives a clearer ImportError message when an optional dependency is missing, including an install hint like pip install mypkg[extra].

Installation

pip install optional-dependency-hint

Requirements

  • Python >=3.8

Quick Start

import optdep

# Declare `tqdm` as an optional dependency of `mypkg`
# and tell users how to install it.
optdep.add("tqdm", "mypkg", "progbar")

import tqdm
# If `tqdm` is missing:
# ImportError: Optional dependency tqdm is not installed.
# You may install it with mypkg by: `pip install mypkg[progbar]`

If you only want the default message without install instructions:

import optdep

optdep.add("tqdm")

import tqdm
# If `tqdm` is missing:
# ImportError: Optional dependency tqdm is not installed.

API

optdep.add(module_name, this_pkg_name=None, extra=None, exist_behavior="skip")

  • module_name (str): target optional dependency module name.
  • this_pkg_name (str | None): your package name shown in hint message.
  • extra (str | None): extra name shown as pkg[extra].
  • exist_behavior ("skip" | "overwrite" | "error"): behavior when the module was already registered.

exist_behavior semantics

  • skip (default): keep old registration.
  • overwrite: replace old registration with the new one.
  • error: raise RuntimeError.

Notes

  • Call optdep.add(...) before importing the optional module.
  • This package registers an import hook via sys.meta_path at import time.

License

MIT

Metadata

Release files for optional-dependency-hint 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optional-dependency-hint 0.1.0
File Size Uploaded Provenance Actions
optional_dependency_hint-0.1.0.tar.gz 4.3 kB Without provenance Details for optional_dependency_hint-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for optional-dependency-hint 0.1.0
File Interpreter ABI Platform Actions
optional_dependency_hint-0.1.0-py3-none-any.whl Python 3 none any Details for optional_dependency_hint-0.1.0-py3-none-any.whl

Total release size: 8.4 kB

Release files / optional_dependency_hint-0.1.0.tar.gz

Download URL optional_dependency_hint-0.1.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8e44674cf5529ba6c99f3d8d40cf0d0a28a64a822aab872a19e611a5873feedf
BLAKE2b-256 checksum
How to use checksums
1f36a9d47e8fdd1be4298d54d5f251595fafc2fa850549ac9ffe9ce0569128f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.22

Release files / optional_dependency_hint-0.1.0-py3-none-any.whl

Download URL optional_dependency_hint-0.1.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0fd85e57853558c62019d8d9f103dcae323dc25b2cdafc6e356428cd324e2b7
BLAKE2b-256 checksum
How to use checksums
f58a3067f73a5c049e2e7ac085e6c9b2fb4a6574311b853702a3ed54a4239eec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.22

Security for optional-dependency-hint 0.1.0

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.0 This release

2 release files 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