nats.py¶
Python3 client for the NATS messaging system.
Getting Started¶
pip install nats-py
You can also optionally install nkeys in order to use the NATS v2.0 decentralized auth features using JWTs.
pip install nats-py[nkeys]
NATS Hello World in Python 🐍
import asyncio
import nats
async def main():
# Connect to NATS!
nc = await nats.connect("demo.nats.io")
# Receive messages on 'foo'
sub = await nc.subscribe("foo")
# Publish a message to 'foo'
await nc.publish("foo", b'Hello from Python!')
# Process a message
msg = await sub.next_msg()
print("Received:", msg)
# Make sure all published messages have reached the server
await nc.flush()
# Close NATS connection
await nc.close()
if __name__ == '__main__':
asyncio.run(main())
- Modules
connect()
- Asyncio Client
- JetStream
jetstream()
publish()
subscribe()
pull_subscribe()
PullSubscription
- Manager
JetStreamManager
JetStreamManager.find_stream_name_by_subject()
JetStreamManager.stream_info()
JetStreamManager.add_stream()
JetStreamManager.update_stream()
JetStreamManager.delete_stream()
JetStreamManager.purge_stream()
JetStreamManager.streams_info()
JetStreamManager.consumers_info()
JetStreamManager.get_msg()
JetStreamManager.delete_msg()
JetStreamManager.get_last_msg()
- KeyValue
- API
Header
StatusCode
Base
PubAck
Placement
ExternalStream
StreamSource
StreamSourceInfo
LostStreamData
StreamState
RetentionPolicy
StorageType
DiscardPolicy
RePublish
StreamConfig
PeerInfo
ClusterInfo
StreamInfo
AckPolicy
DeliverPolicy
ReplayPolicy
ConsumerConfig
SequenceInfo
ConsumerInfo
AccountLimits
Tier
APIStats
AccountInfo
RawStreamMsg
KeyValueConfig
StreamPurgeRequest
ObjectStoreConfig
ObjectLink
ObjectMetaOptions
ObjectMeta
ObjectInfo
- NUID
- Errors
Error
TimeoutError
NoRespondersError
StaleConnectionError
OutboundBufferLimitError
UnexpectedEOF
FlushTimeoutError
ConnectionClosedError
SecureConnRequiredError
SecureConnWantedError
SecureConnFailedError
BadSubscriptionError
BadSubjectError
SlowConsumerError
BadTimeoutError
AuthorizationError
NoServersError
JsonParseError
MaxPayloadError
DrainTimeoutError
ConnectionDrainingError
ConnectionReconnectingError
InvalidUserCredentialsError
InvalidCallbackTypeError
ProtocolError
NotJSMessageError
MsgAlreadyAckdError
- JetStream Errors
Error
APIError
ServiceUnavailableError
ServerError
NotFoundError
BadRequestError
NoStreamResponseError
ConsumerSequenceMismatchError
BucketNotFoundError
BadBucketError
KeyValueError
KeyDeletedError
KeyNotFoundError
KeyWrongLastSequenceError
NoKeysError
KeyHistoryTooLargeError
InvalidBucketNameError
InvalidObjectNameError
BadObjectMetaError
LinkIsABucketError
DigestMismatchError
ObjectNotFoundError
ObjectDeletedError
ObjectAlreadyExists
- Deprecated Errors
NatsError
ErrConnectionClosed
ErrDrainTimeout
ErrInvalidUserCredentials
ErrInvalidCallbackType
ErrConnectionReconnecting
ErrConnectionDraining
ErrMaxPayload
ErrStaleConnection
ErrJsonParse
ErrSecureConnRequired
ErrSecureConnWanted
ErrSecureConnFailed
ErrBadSubscription
ErrBadSubject
ErrSlowConsumer
ErrTimeout
ErrBadTimeout
ErrAuthorization
ErrNoServers
- Releases
Site¶
License¶
Unless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.