{"id":4826,"library":"types-greenlet","title":"types-greenlet","description":"types-greenlet provides external type hints (stubs) for the `greenlet` library, enabling static type checkers like MyPy and Pyright to analyze code using `greenlet` effectively. It is part of the `typeshed` project, which maintains a collection of high-quality type annotations for many Python packages. Releases are frequent, often daily, to keep pace with updates in the `greenlet` library and general typeshed improvements. The current version, 3.4.0.20260409, aims to provide accurate annotations for `greenlet==3.3.*`.","status":"active","version":"3.4.0.20260409","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","type-checking","greenlet","typeshed"],"install":[{"cmd":"pip install types-greenlet greenlet","lang":"bash","label":"Install stubs and runtime library"}],"dependencies":[{"reason":"Provides runtime functionality; types-greenlet only provides type annotations for it.","package":"greenlet","optional":false},{"reason":"A common static type checker that utilizes these stubs.","package":"mypy","optional":true},{"reason":"Another common static type checker that utilizes these stubs.","package":"pyright","optional":true}],"imports":[{"note":"You import the runtime `greenlet` library; types-greenlet provides annotations for it implicitly to type checkers.","symbol":"greenlet","correct":"import greenlet"},{"symbol":"greenlet.greenlet","correct":"from greenlet import greenlet"},{"symbol":"greenlet.getcurrent","correct":"from greenlet import getcurrent"}],"quickstart":{"code":"import greenlet\n\ndef worker_function(name: str) -> str:\n    print(f\"Worker {name} started.\")\n    # Simulate some work, then switch back to parent\n    result = f\"Hello from {name}!\"\n    parent = greenlet.getcurrent().parent\n    if parent:\n        return parent.switch(result)\n    return result\n\ndef main_function():\n    main = greenlet.getcurrent()\n    g1 = greenlet.greenlet(worker_function)\n    g2 = greenlet.greenlet(worker_function)\n\n    print(\"Main function: Switching to g1\")\n    res1 = g1.switch(\"Alice\")\n    print(f\"Main function: Received {res1}\")\n\n    print(\"Main function: Switching to g2\")\n    res2 = g2.switch(\"Bob\")\n    print(f\"Main function: Received {res2}\")\n\n    print(\"Main function: All done.\")\n\nif __name__ == \"__main__\":\n    main_function()\n\n# To verify type checking (requires mypy installed):\n# Save this code as `example.py`\n# Run `mypy example.py` in your terminal. With types-greenlet installed, it should pass without errors for greenlet-specific types.","lang":"python","description":"This example demonstrates basic usage of the `greenlet` library. When `types-greenlet` is installed, a static type checker will understand the types associated with `greenlet.greenlet`, `greenlet.getcurrent()`, and their methods, providing better analysis and error detection without needing direct imports from `types-greenlet` itself."},"warnings":[{"fix":"Understand that types-greenlet is a development dependency for type checking, not a runtime dependency.","message":"Typeshed stubs, including types-greenlet, only provide type annotations for static analysis and do not add any runtime behavior or functionality to the actual `greenlet` library. They are solely for type checkers.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Carefully manage stub package versions. It's recommended to either use the same version bounds as the runtime `greenlet` package (e.g., `types-greenlet~=X.Y`) or pin the stubs to a known-good version and update periodically (e.g., `types-greenlet==X.Y.Z.YYYYMMDD`).","message":"Any version bump of `types-greenlet` (or any typeshed stub package) can potentially introduce changes that might cause your code to fail type checks, even if the runtime library's API hasn't changed. This is due to evolving type definitions or stricter annotations within typeshed.","severity":"breaking","affected_versions":"All versions"},{"fix":"For `gevent` applications, look for `types-gevent` if available, or rely on any inline types provided by `gevent` itself.","message":"The `types-greenlet` package provides stubs specifically for the `greenlet` library. While `gevent` builds upon `greenlet`, it introduces its own `Greenlet` class and API. Using `types-greenlet` for `gevent` code might lead to incorrect or incomplete type checking, as it won't cover `gevent`-specific abstractions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Stay informed about `greenlet`'s typing strategy. If it adopts inline types, `types-greenlet` may no longer be necessary or recommended.","message":"If the `greenlet` library were to start shipping its own inline type annotations (via a `py.typed` file), the external stubs provided by `types-greenlet` might eventually become obsolete and could be removed from typeshed after a transition period.","severity":"deprecated","affected_versions":"Future versions of greenlet, if it adds inline types."}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}