Python client

Obtaining the Pulsar Python client

Pulsar Python client library is available from PyPI.

You can easily install it with the pip tool:

pip install pulsar-client

Reference Documentation

Detailed documentation for the Pulsar Python client library can be found at https://pulsar.apache.org/api/python/.

Producer Example

import pulsar
client = pulsar.Client('pulsar+ssl://prod.my-company.cloud.streamlio.com:6651'
authentication=pulsar.AuthenticationToken('s.JzdWIiOiJKb2UifQ'))
producer = client.create_producer('my-tenant/my-namespace/my-topic',
schema=pulsar.schema.StringSchema())
producer.send('Hello!')
client.close()

Consumer Example

import pulsar
client = pulsar.Client('pulsar+ssl://prod.my-company.cloud.streamlio.com:6651'
authentication=pulsar.AuthenticationToken('s.JzdWIiOiJKb2UifQ'))
consumer = client.subscribe('my-tenant/my-namespace/my-topic',
subscription_name='my-subscription'
schema=pulsar.schema.StringSchema())
while True:
msg = consumer.receive()
try:
print("Received message '{}' id='{}'".format(msg.value(), msg.message_id()))
# Acknowledge successful processing of the message
consumer.acknowledge(msg)
except:
# Message failed to be processed
consumer.negative_acknowledge(msg)
client.close()

_____ Copyright 2019 Streamlio, Inc. Apache, Apache BookKeeper, Apache Pulsar and associated open source project names are trademarks of the Apache Software Foundation.