All Projects → ably → ably-python

ably / ably-python

Licence: Apache-2.0 License
Python REST client library SDK for Ably realtime messaging service

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to ably-python

ably-cocoa
iOS, tvOS and macOS Objective-C and Swift client library SDK for Ably realtime messaging service
Stars: ✭ 33 (+65%)
Mutual labels:  client-library
Milvasoft.Iyzipay
Iyzico client for .Net 6
Stars: ✭ 15 (-25%)
Mutual labels:  client-library
cybr-cli
A "Swiss Army Knife" command-line interface (CLI) for easy human and non-human interaction with @cyberark suite of products.
Stars: ✭ 45 (+125%)
Mutual labels:  client-library
js-client-library
TimeTac Client Library is a thin wrapper for client to make api request.
Stars: ✭ 11 (-45%)
Mutual labels:  client-library
node-meraki-dashboard
A modern node.js client library for using the Meraki Dashboard API.
Stars: ✭ 20 (+0%)
Mutual labels:  client-library
circles-core
Common methods to interact with the Circles ecosystem
Stars: ✭ 22 (+10%)
Mutual labels:  client-library
kubernetes-client-lambda
one-line kubernetes client: light-weight, lambda-styled, easy-testing. For a simplified kubernetes programming.
Stars: ✭ 47 (+135%)
Mutual labels:  client-library
python-cozify
Unofficial Cozify Python bindings and helpers
Stars: ✭ 15 (-25%)
Mutual labels:  client-library
braze-php-sdk
A PHP client to interact with Braze API
Stars: ✭ 15 (-25%)
Mutual labels:  client-library
ably-dotnet
.NET, Xamarin and Mono client library SDK for Ably realtime messaging service
Stars: ✭ 32 (+60%)
Mutual labels:  client-library
iyzipay-ruby
iyzipay api ruby client
Stars: ✭ 37 (+85%)
Mutual labels:  client-library
goql
A GraphQL client package written in Go.
Stars: ✭ 17 (-15%)
Mutual labels:  client-library
c
Official C client library for Kubernetes
Stars: ✭ 83 (+315%)
Mutual labels:  client-library
ably-php
PHP client library SDK for Ably realtime messaging service
Stars: ✭ 41 (+105%)
Mutual labels:  client-library
skyscanner-flight-api-client
Published on Maven Central Java Client for a Skyscanner Flight Search API hosted in Rapid API
Stars: ✭ 15 (-25%)
Mutual labels:  client-library
streamr-client-javascript
JS library for interacting with Streamr APIs: publishing and subscribing to data, creating streams, etc.
Stars: ✭ 35 (+75%)
Mutual labels:  client-library
agollo
🚀Go client for ctrip/apollo (https://github.com/apolloconfig/apollo)
Stars: ✭ 563 (+2715%)
Mutual labels:  client-library
embed-client
🎼 Sheet Music & Tabs Embed JavaScript Client
Stars: ✭ 43 (+115%)
Mutual labels:  client-library
kong-java-client
Java Client for Kong API Gateway configuration
Stars: ✭ 69 (+245%)
Mutual labels:  client-library
in3-legacy
[Deprecated] Typescript-version of the IN3 client.
Stars: ✭ 69 (+245%)
Mutual labels:  client-library

ably-python

.github/workflows/check.yml PyPI version

Overview

This is a Python client library for Ably. The library currently targets the Ably 1.1 client library specification.

Running example

import asyncio
from ably import AblyRest

async def main():
    async with AblyRest('api:key') as ably:
        channel = ably.channels.get("channel_name")

if __name__ == "__main__":
    asyncio.run(main())

Installation

The client library is available as a PyPI package.

Requirements

From PyPI

pip install ably

Or, if you need encryption features:

pip install 'ably[crypto]'

Locally

git clone https://github.com/ably/ably-python.git
cd ably-python
python setup.py install

Breaking API Changes in Version 1.2.0

Please see our Upgrade / Migration Guide for notes on changes you need to make to your code to update it to use the new API introduced by version 1.2.0.

Usage

All examples assume a client and/or channel has been created in one of the following ways:

With closing the client manually:

from ably import AblyRest

async def main(): 
    client = AblyRest('api:key')
    channel = client.channels.get('channel_name')
    await client.close()

When using the client as a context manager, this will ensure that client is properly closed while leaving the with block:

from ably import AblyRest

async def main():
    async with AblyRest('api:key') as ably:
        channel = ably.channels.get("channel_name")

You can define the logging level for the whole library, and override for a specific module:

import logging
import ably

logging.getLogger('ably').setLevel(logging.WARNING)
logging.getLogger('ably.rest.auth').setLevel(logging.INFO)

You need to add a handler to see any output:

logger = logging.getLogger('ably')
logger.addHandler(logging.StreamHandler())

Publishing a message to a channel

await channel.publish('event', 'message')

Querying the History

message_page = await channel.history() # Returns a PaginatedResult
message_page.items # List with messages from this page
message_page.has_next() # => True, indicates there is another page
next_page = await message_page.next() # Returns a next page
next_page.items # List with messages from the second page

Current presence members on a channel

members_page = await channel.presence.get() # Returns a PaginatedResult
members_page.items
members_page.items[0].client_id # client_id of first member present

Querying the presence history

presence_page = await channel.presence.history() # Returns a PaginatedResult
presence_page.items
presence_page.items[0].client_id # client_id of first member

Symmetric end-to-end encrypted payloads on a channel

When a 128 bit or 256 bit key is provided to the library, all payloads are encrypted and decrypted automatically using that key on the channel. The secret key is never transmitted to Ably and thus it is the developer's responsibility to distribute a secret key to both publishers and subscribers.

key = ably.util.crypto.generate_random_key()
channel = rest.channels.get('communication', cipher={'key': key})
channel.publish(u'unencrypted', u'encrypted secret payload')
messages_page = await channel.history()
messages_page.items[0].data #=> "sensitive data"

Generate a Token

Tokens are issued by Ably and are readily usable by any client to connect to Ably:

token_details = await client.auth.request_token()
token_details.token # => "xVLyHw.CLchevH3hF....MDh9ZC_Q"
new_client = AblyRest(token=token_details)
await new_client.close()

Generate a TokenRequest

Token requests are issued by your servers and signed using your private API key. This is the preferred method of authentication as no secrets are ever shared, and the token request can be issued to trusted clients without communicating with Ably.

token_request = await client.auth.create_token_request(
    {
        'client_id': 'jim',
        'capability': {'channel1': '"*"'},
        'ttl': 3600 * 1000, # ms
    }
)
# => {"id": ...,
#     "clientId": "jim",
#     "ttl": 3600000,
#     "timestamp": ...,
#     "capability": "{\"*\":[\"*\"]}",
#     "nonce": ...,
#     "mac": ...}

new_client = AblyRest(token=token_request)
await new_client.close()

Fetching your application's stats

stats = await client.stats() # Returns a PaginatedResult
stats.items
await client.close()

Fetching the Ably service time

await client.time()
await client.close()

Resources

Visit https://ably.com/documentation for a complete API reference and more examples.

Requirements

This SDK supports Python 3.7+.

We regression-test the SDK against a selection of Python versions (which we update over time, but usually consists of mainstream and widely used versions). Please refer to check.yml for the set of versions that currently undergo CI testing.

Known Limitations

Currently, this SDK only supports Ably REST. However, you can use the MQTT adapter to implement Ably's Realtime features using Python.

Support, Feedback and Troubleshooting

If you find any compatibility issues, please do raise an issue in this repository or contact Ably customer support for advice.

Support, feedback and troubleshooting

Please visit https://ably.com/support for access to our knowledge base and to ask for any assistance.

You can also view the community reported GitHub issues.

To see what has changed in recent versions of Bundler, see the CHANGELOG.

Contributing

For guidance on how to contribute to this project, see CONTRIBUTING.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].