Install & Compatibility
Where this runs
tested against v0.1.3 · 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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.3MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
BlockingConnection
✓ from pika_stubs import BlockingConnection
✗ from pika_stubs import BlockingConnection
This quickstart demonstrates how pika-stubs enhances type checking for a basic Pika consumer. After installing `pika-stubs` alongside `pika` and `mypy`, running `mypy` on the Python file will utilize the provided type information to catch potential errors or provide better IDE suggestions. The example uses environment variables for RabbitMQ host for flexibility.
# consumer.py
import pika
import os
def callback(ch: pika.channel.Channel, method: pika.spec.Basic.Deliver, properties: pika.spec.BasicProperties, body: bytes) -> None:
print(f" [x] Received {body.decode()}")
def main() -> None:
rabbitmq_host = os.environ.get('RABBITMQ_HOST', 'localhost')
connection = pika.BlockingConnection(
pika.ConnectionParameters(host=rabbitmq_host)
)
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_consume(queue='hello', on_message_callback=callback, auto_ack=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
try:
channel.start_consuming()
except KeyboardInterrupt:
channel.stop_consuming()
finally:
connection.close()
if __name__ == '__main__':
main()
# To run mypy with pika-stubs:
# 1. pip install pika pika-stubs mypy
# 2. RABBITMQ_HOST=localhost python consumer.py (in one terminal)
# 3. mypy consumer.py (in another terminal)
Debug
Known issues
breakingPika-stubs requires Python 3.8 or newer. Attempting to install on older Python versions (e.g., 3.7) will result in an installation failure.fixEnsure your Python environment is 3.8 or newer before installing `pika-stubs`. Consider using a virtual environment.
affects: <=0.1.3 on Python <3.8
gotchaThis library (pika-stubs) appears to be unmaintained. Its last release was in June 2020, and its PyPI status is '1 - Planning'. More actively maintained alternatives like `types-pika-ts` (part of typeshed) or `types-pika` may offer more up-to-date and complete typings for recent Pika versions.fixFor newer Pika versions or more active maintenance, consider `pip install types-pika-ts` or `pip install types-pika` instead. Consult their respective documentation for usage.
affects: All versions of pika-stubs (0.1.3)
Upgrade
Version history
0.1.3latest on PyPI · released Jun 10, 2020
Audit
Dependencies
pikarequiredProvides type stubs for the pika library; essential for its functionality.
mypyrequiredA static type checker that utilizes these stubs for type inference.