{"id":4941,"library":"extras","title":"Useful extra bits for Python","description":"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.","status":"abandoned","version":"1.0.0","language":"python","source_language":"en","source_url":"https://github.com/testing-cabal/extras","tags":["utility","standard library extensions","module loading","attribute checking"],"install":[{"cmd":"pip install extras","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Used for attempting to import modules or specific attributes from modules, returning None on failure rather than raising an ImportError.","symbol":"try_import","correct":"from extras import try_import"},{"note":"Similar to try_import, but for multiple items from a module.","symbol":"try_imports","correct":"from extras import try_imports"},{"note":"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.","symbol":"safe_hasattr","correct":"from extras import safe_hasattr"}],"quickstart":{"code":"from extras import try_import\n\n# Attempt to import a module, returning None if it fails\nrequests = try_import(\"requests\")\n\nif requests:\n    print(\"The 'requests' library was imported successfully.\")\n    try:\n        # Use an external service for a live example, if requests is available\n        response = requests.get(\"https://api.github.com\")\n        print(f\"GitHub API status: {response.status_code}\")\n    except Exception as e:\n        print(f\"Error accessing GitHub API: {e}\")\nelse:\n    print(\"The 'requests' library is not installed. Skipping API call.\")","lang":"python","description":"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."},"warnings":[{"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.","message":"The '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.","severity":"breaking","affected_versions":"<=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"search_vec":"'2016':47 'activ':53 'attempt':36 'attribut':39,61 'bit':3 'check':40,62 'cleaner':29 'code':24 'develop':21 'extens':12,58 'extra':2,7 'import':35 'indic':48 'last':42 'librari':8,17,57 'like':32 'load':60 'longer':52 'maintain':54 'make':23 'may':46 'modul':34,59 'offer':30 'origin':20 'project':28 'provid':9 'python':5,15 'releas':43 'robust':33 'safe':38 'small':10 'standard':16,56 'testtool':27 'use':1,11 'util':31,55 'within':25","created_at":"2026-04-12T16:47:16.173432+00:00","updated_at":"2026-04-16T14:53:55.044729+00:00","problems":[{"fix":"Install the library using pip: `pip install extras`","cause":"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`.","error":"ModuleNotFoundError: No module named 'extras'"},{"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`.","cause":"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.","error":"AttributeError: module 'extras' has no attribute 'some_non_existent_utility'"},{"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`).","cause":"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`.","error":"AttributeError: 'NoneType' object has no attribute 'some_method'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.0.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/testing-cabal/extras","docs":null,"changelog":null,"pypi":"https://pypi.org/project/extras/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-30","next_check":"2026-07-28","install_tag":null}}