{"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":"en","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,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}