Registry / testing / extras

extras

JSON →
library1.0.0pypypi✓ verified 28d ago

The 'extras' library provides small, useful extensions to the Python standard library. It was originally developed to make code within the 'testtools' project cleaner, offering utilities like robust module import attempts and safe attribute checking. The last release was in May 2016, indicating it is no longer actively maintained.

pip install extras
INSTALL
IMPORT
SIG · EXTRAS
E
extras
testingpythonv1.0.0
Install
1.5s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

try_import
✓ from extras import try_import
Used for attempting to import modules or specific attributes from modules, returning None on failure rather than raising an ImportError.
try_imports
✓ from extras import try_imports
Similar to try_import, but for multiple items from a module.
safe_hasattr
✓ from extras import safe_hasattr
A utility to check for an attribute's existence on an object without risking an AttributeError if the attribute lookup itself is complex or has side effects.

This quickstart demonstrates the `try_import` function, a core utility from the 'extras' library. It attempts to import the 'requests' library and then uses it if successful, gracefully handling cases where 'requests' might not be installed. This pattern is useful for optional dependencies.

from extras import try_import # Attempt to import a module, returning None if it fails requests = try_import("requests") if requests: print("The 'requests' library was imported successfully.") try: # Use an external service for a live example, if requests is available response = requests.get("https://api.github.com") print(f"GitHub API status: {response.status_code}") except Exception as e: print(f"Error accessing GitHub API: {e}") else: print("The 'requests' library is not installed. Skipping API call.")
Debug
Known issues
breakingThe 'extras' library has not been updated since May 2016. It may not be compatible with modern Python versions (e.g., Python 3.8+) or contain practices that are now considered outdated or superseded by standard library features. Use with caution for new projects.
fix
Thoroughly test compatibility with your target Python version. Consider reimplementing desired functionalities using modern Python features or more actively maintained libraries if 'extras' causes issues.
affects: <=1.0.0
gotchaThe name 'extras' can be confusing due to its overlap with the concept of 'extras' (optional dependencies) in Python packaging (e.g., `pip install package[extra_feature]`). This library 'extras' is a collection of utilities, distinct from packaging 'extras'. Also, there are other similarly named PyPI packages like 'python-extras' or 'streamlit-extras' which are different projects.
fix
Ensure you are importing from the correct 'extras' package if you have multiple packages with similar names installed. Always refer to the specific GitHub repository or PyPI page to confirm the correct project.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'extras'
The 'extras' library has not been installed in your Python environment, or it's not accessible from the current environment. For Python versions prior to 3.6, the error would likely be `ImportError: No module named extras`.
fix
Install the library using pip: `pip install extras`
AttributeError: module 'extras' has no attribute 'some_non_existent_utility'
You are attempting to access a function, class, or attribute from the `extras` module that does not exist or is misspelled. This can happen if you expect a utility (e.g., `safe_hasattr` or `try_imports`) to be directly under the `extras` module, but it might be nested within a submodule or not present in the installed version.
fix
Consult the `extras` library's documentation or source code to verify the correct name and path of the utility you intend to use. For example, if it's within a submodule, you might need to import it as `from extras.submodule import correct_utility`.
AttributeError: 'NoneType' object has no attribute 'some_method'
This error often occurs when using `extras.try_imports` (or a similar 'robust module import' utility from the library). If `try_imports` fails to import the specified module, it typically returns `None`. Subsequent code then attempts to call a method or access an attribute on this `None` object, leading to an `AttributeError`.
fix
Always check the return value of `extras.try_imports` to ensure a module was successfully loaded before attempting to use it. Implement a conditional check or a fallback mechanism to handle cases where the import fails (i.e., when `try_imports` returns `None`).
Upgrade
Version history
1.0.0latest on PyPI · released May 18, 2016
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
extras — pip install extras · libregistry