{"id":8743,"library":"types-pika-ts","title":"Typing Stubs for Pika","description":"This library provides high-quality static type checking stubs for the `pika` Python library, which is a popular AMQP 0-9-1 client for Python. It is part of the community-maintained Typeshed project. The current version is 1.3.0.20260408, with releases tied to updates in the `pika` library and general typeshed maintenance.","status":"active","version":"1.3.0.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","pika","typeshed","type-checking"],"install":[{"cmd":"pip install types-pika-ts","lang":"bash","label":"Install stubs"},{"cmd":"pip install pika types-pika-ts","lang":"bash","label":"Install pika with stubs"}],"dependencies":[],"imports":[{"note":"This library provides typing stubs for the `pika` runtime library. `types-pika-ts` itself is not imported; its presence in your environment allows type checkers (like MyPy) to understand the types and signatures of objects imported from `pika`.","symbol":"pika","correct":"import pika"}],"quickstart":{"code":"import pika\nfrom pika.adapters.blocking_connection import BlockingConnection, URLParameters\nimport os\n\n# This code demonstrates how to use pika, for which types-pika-ts provides stubs.\n# The stubs enable static analysis of pika code using type checkers like MyPy.\n\ntry:\n    # Connect to RabbitMQ using a connection URL. \n    # Use an environment variable for actual deployments.\n    rabbitmq_url = os.environ.get('RABBITMQ_URL', 'amqp://guest:guest@localhost:5672/%2F')\n    connection = BlockingConnection(URLParameters(rabbitmq_url))\n    channel = connection.channel()\n\n    channel.queue_declare(queue='hello')\n    message_body = 'Hello World!'\n    channel.basic_publish(exchange='', routing_key='hello', body=message_body)\n    print(f\" [x] Sent '{message_body}'\")\n    \n    connection.close()\n\nexcept pika.exceptions.AMQPConnectionError as e:\n    print(f\" [!] Could not connect to RabbitMQ: {e}\")\n    print(\"     Ensure RabbitMQ is running or adjust the RABBITMQ_URL environment variable.\")\nexcept Exception as e:\n    print(f\" [!] An unexpected error occurred: {e}\")\n\n# To verify type checking:\n# 1. Ensure 'pika' and 'types-pika-ts' are installed.\n# 2. Run 'mypy your_script_name.py' in your terminal.\n# MyPy will use the stubs to check the pika calls for type consistency.","lang":"python","description":"This quickstart demonstrates a basic Pika usage pattern. Installing `types-pika-ts` alongside `pika` allows type checkers like MyPy to provide rich static analysis for Pika's API, catching potential type-related errors before runtime. The code will execute Pika operations (if RabbitMQ is available) and is designed to be analyzed by a type checker."},"warnings":[{"fix":"Remember that `types-pika-ts` is a development dependency, not a runtime dependency that changes how `pika` behaves. Install it only for environments where type checking occurs.","message":"Type stubs (like `types-pika-ts`) do not add any runtime functionality or behavior to your application. They are solely used by static type checkers (e.g., MyPy, Pyright) during development to verify type correctness.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always try to install `types-pika-ts` version that matches or is compatible with your `pika` version. Frequently update both packages. For example, `pip install 'pika==1.3.*' 'types-pika-ts==1.3.*'`.","message":"Mismatched versions between the `pika` library and its corresponding `types-pika-ts` stubs can lead to incorrect type checking errors or omissions. If `pika` updates its API, older stubs might not reflect the changes.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Integrate a type checker into your development workflow. Run `mypy your_script.py` regularly or configure it as part of your CI/CD pipeline.","message":"Type checking benefits from `types-pika-ts` are only realized when a static type checker (like MyPy) is explicitly run. Simply installing the stubs will not automatically validate your code at runtime.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"If `pika` is missing, install it: `pip install pika`. If `pika` is installed but stubs are missing, install the stubs: `pip install types-pika-ts`.","cause":"You have imported 'pika' in your code, but either 'pika' itself is not installed, or 'pika' is installed but its corresponding type stubs (`types-pika-ts`) are missing, and MyPy cannot infer its types.","error":"error: Cannot find implementation or type stub for module 'pika'"},{"fix":"Ensure `types-pika-ts` is installed (`pip install types-pika-ts`). Verify that `pika` and `types-pika-ts` versions are compatible. If still encountering issues, try clearing MyPy's cache by removing the `.mypy_cache` directory in your project root.","cause":"MyPy is reporting that it cannot find the `BlockingConnection` attribute on the `pika` module. This typically indicates that the `types-pika-ts` stubs are either not installed, are outdated relative to your `pika` version, or MyPy's cache is stale.","error":"error: Module 'pika' has no attribute 'BlockingConnection' [reportGeneralTypeIssues]"}]}