{"library":"pulsar-client","title":"Pulsar Python Client","description":"The `pulsar-client` library provides a Python API for interacting with Apache Pulsar, a distributed messaging and streaming platform. It allows applications to produce and consume messages from Pulsar topics, supporting various messaging patterns and schema management. The current version is 3.10.0, with releases occurring periodically to keep pace with the main Pulsar project and ensure compatibility with new broker features.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install pulsar-client"],"cli":null},"imports":["from pulsar import Client","from pulsar import Producer","from pulsar import Consumer","from pulsar import MessageId","from pulsar import Schema","from pulsar import ConsumerType"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pulsar\nimport time\nimport os\n\n# --- Configuration ---\n# Ensure a Pulsar broker is running, e.g., locally via Docker:\n# docker run -it -p 6650:6650 -p 8080:8080 apachepulsar/pulsar:latest bin/pulsar standalone\nPULSAR_BROKER_URL = os.environ.get('PULSAR_BROKER_URL', 'pulsar://localhost:6650')\nTOPIC_NAME = 'persistent://public/default/my-python-topic-qs'\nSUBSCRIPTION_NAME = 'my-python-subscription-qs'\n\nprint(f\"Connecting to Pulsar at: {PULSAR_BROKER_URL}\")\n\n# --- Producer ---\ntry:\n    print(\"\\n--- Starting Producer ---\")\n    client_producer = pulsar.Client(PULSAR_BROKER_URL)\n    producer = client_producer.create_producer(TOPIC_NAME)\n\n    for i in range(3):\n        message_data = f\"hello-pulsar-message-{i}\".encode('utf-8')\n        producer.send(message_data)\n        print(f\"Producer sent: {message_data.decode()}\")\n        time.sleep(0.1) # Small delay\n\n    producer.close()\n    client_producer.close()\n    print(\"--- Producer finished. ---\")\nexcept Exception as e:\n    print(f\"Producer error: {e}\")\n\ntime.sleep(1) # Give a moment for messages to be available in the topic\n\n# --- Consumer ---\ntry:\n    print(\"\\n--- Starting Consumer ---\")\n    client_consumer = pulsar.Client(PULSAR_BROKER_URL)\n    consumer = client_consumer.subscribe(TOPIC_NAME, SUBSCRIPTION_NAME, consumer_type=pulsar.ConsumerType.Shared)\n\n    print(\"Consumer waiting for messages...\")\n    received_count = 0\n    # We expect 3 messages from the producer\n    while received_count < 3:\n        try:\n            msg = consumer.receive(timeout_millis=3000) # Wait up to 3 seconds\n            if msg:\n                print(f\"Consumer received: '{msg.data().decode('utf-8')}' (ID: {msg.message_id()})\")\n                consumer.acknowledge(msg)\n                received_count += 1\n            else:\n                print(\"Consumer timed out waiting for message. Retrying...\")\n        except Exception as msg_err:\n            print(f\"Error receiving individual message: {msg_err}\")\n            break # Exit on error\n    \n    consumer.close()\n    client_consumer.close()\n    print(\"---\n Consumer finished. ---\")\nexcept Exception as e:\n    print(f\"Consumer error: {e}\")\n\nprint(\"\\nQuickstart demonstration complete.\")","lang":"python","description":"This quickstart demonstrates how to produce and consume messages using the `pulsar-client` library. It assumes a Pulsar broker is running and accessible (e.g., via `pulsar://localhost:6650`). The script first acts as a producer, sending three messages to a topic, then switches to a consumer, subscribing to the same topic and receiving those messages. Crucially, it shows proper resource management by calling `.close()` on clients, producers, and consumers. The Pulsar broker URL can be configured via the `PULSAR_BROKER_URL` environment variable.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"3.8.0","pypi_latest":"3.11.0","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.8,"avg_import_s":0.05,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pulsar-client","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.05,"mem_mb":2.3,"disk_size":"41.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pulsar-client","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0.03,"mem_mb":2.3,"disk_size":"41M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pulsar-client","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.08,"mem_mb":2.4,"disk_size":"43.6M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pulsar-client","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0.07,"mem_mb":2.4,"disk_size":"43M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pulsar-client","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.06,"mem_mb":2.1,"disk_size":"35.5M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pulsar-client","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.06,"mem_mb":2.1,"disk_size":"35M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pulsar-client","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.06,"mem_mb":2.5,"disk_size":"35.2M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pulsar-client","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.05,"mem_mb":2.3,"disk_size":"35M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pulsar-client","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.04,"mem_mb":2.1,"disk_size":"34.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pulsar-client","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2,"import_time_s":0.03,"mem_mb":2.1,"disk_size":"38M"}]}}