SDKs overview
Ably provides a suite of Software Development Kits (SDKs) designed to simplify integration with its real-time messaging platform. These SDKs abstract the complexities of WebSocket connections, message publishing and subscribing, presence management, and authentication, allowing developers to focus on application logic. The SDKs support various programming languages and platforms, facilitating the development of real-time features across web, mobile, and backend environments. Each SDK is maintained to ensure compatibility with the latest platform features and protocols, including the Ably Realtime API.
A core aspect of Ably's SDKs is their focus on reliability and resilience. They include features such as automatic re-connection with exponential backoff, message queuing during disconnections, and idempotent message publishing. This design helps ensure that applications maintain connectivity and message integrity even in challenging network conditions. Developers can find detailed guides and API references for each SDK within the Ably SDK documentation.
Official SDKs by language
Ably offers official SDKs for a broad range of programming languages and platforms, catering to diverse development ecosystems. These SDKs are actively maintained by Ably and provide idiomatic interfaces for each language, ensuring a natural development experience. The table below outlines the primary official SDKs, their respective package identifiers, installation commands, and maturity status, as described in the Ably SDK reference.
| Language/Platform | Package/Module | Install Command (Example) | Maturity |
|---|---|---|---|
| JavaScript | ably |
npm install ably or yarn add ably |
Stable |
| TypeScript | ably |
npm install ably (includes TypeScript definitions) |
Stable |
| Python | ably |
pip install ably |
Stable |
| Ruby | ably |
gem install ably |
Stable |
| PHP | ably/ably-php |
composer require ably/ably-php |
Stable |
| Java | io.ably:ably-java |
Maven: Add dependency; Gradle: implementation 'io.ably:ably-java:x.y.z' |
Stable |
| Go | github.com/ably/ably-go |
go get github.com/ably/ably-go |
Stable |
| C# (.NET) | Ably |
dotnet add package Ably |
Stable |
| Swift | Ably.swift |
Swift Package Manager, CocoaPods, or Carthage | Stable |
| Kotlin | io.ably:ably-kotlin |
Gradle: implementation 'io.ably:ably-kotlin:x.y.z' |
Stable |
| Flutter | ably_flutter |
flutter pub add ably_flutter |
Stable |
| React Native | ably-react-native |
npm install ably-react-native |
Stable |
| Rust | ably |
Add to Cargo.toml: ably = "x.y.z" |
Stable |
| C++ | ably-cpp |
Manual build or package manager (details in Ably C++ SDK documentation) | Stable |
Installation
Installation procedures for Ably SDKs typically follow the standard practices for each respective language or platform. For most package managers, a single command is sufficient to add the Ably library to a project. Specific version numbers should be checked against the official Ably SDK documentation for the latest stable releases.
JavaScript/TypeScript (npm/Yarn)
For web applications or Node.js environments, the Ably JavaScript SDK is available via npm or Yarn:
npm install ably
# or
yarn add ably
Python (pip)
Python developers can install the Ably SDK using pip:
pip install ably
Java (Maven/Gradle)
For Java projects, the Ably SDK can be integrated using Maven or Gradle. Below is a Maven dependency example:
<dependency>
<groupId>io.ably</groupId>
<artifactId>ably-java</artifactId>
<version>1.x.x</version>
</dependency>
And a Gradle example:
implementation 'io.ably:ably-java:1.x.x'
Go
Go applications can add the Ably Go SDK using the go get command:
go get github.com/ably/ably-go
C# (.NET)
For .NET projects, the Ably SDK is available as a NuGet package:
dotnet add package Ably
Flutter (pub)
Flutter developers can add the Ably Flutter plugin using flutter pub add:
flutter pub add ably_flutter
Quickstart example
This quickstart example demonstrates how to connect to Ably, subscribe to a channel, and publish a message using the JavaScript SDK. This pattern is broadly similar across other Ably SDKs, with language-specific syntax variations. Before running this code, ensure you have an Ably API key.
import Ably from 'ably';
// Replace 'YOUR_ABLY_API_KEY' with your actual Ably API key
const ably = new Ably.Realtime('YOUR_ABLY_API_KEY');
ably.connection.on('connected', () => {
console.log('Connected to Ably!');
const channel = ably.channels.get('my-first-channel');
// Subscribe to messages on the channel
channel.subscribe('my-event', (message) => {
console.log('Received message:', message.data);
});
// Publish a message to the channel
channel.publish('my-event', { text: 'Hello, Ably!' }, (err) => {
if (err) {
console.error('Error publishing message:', err);
} else {
console.log('Message published successfully.');
}
});
// You can also publish without waiting for subscription confirmation for simple cases
// channel.publish('another-event', 'Just a string message');
});
ably.connection.on('failed', (error) => {
console.error('Ably connection failed:', error);
});
// To disconnect after some time (optional)
// setTimeout(() => {
// ably.close();
// console.log('Disconnected from Ably.');
// }, 10000);
This example initializes the Ably Realtime client with an API key. It then establishes a connection, subscribes to a channel named 'my-first-channel' for messages with the event name 'my-event', and publishes a sample message. The connection.on('connected', ...) and connection.on('failed', ...) handlers provide feedback on the connection status. More advanced features, such as presence, message history, and push notifications, are covered in the Ably Getting Started guide.
Community libraries
While Ably maintains a comprehensive set of official SDKs, the developer community occasionally contributes libraries and integrations for niche use cases, less common languages, or specific framework adaptations. These community-driven projects can extend Ably's reach and offer alternative approaches to integration. However, it is important to note that community libraries may not offer the same level of support, maintenance, or feature parity as official SDKs. Developers should review the project's documentation, community activity, and licensing before incorporating them into production systems.
Examples of community contributions might include integrations with specific frontend frameworks not directly covered by an official SDK (e.g., Svelte, Vue.js plugins beyond basic JavaScript), or specialized libraries for embedded systems. Developers looking for such resources can often find them on platforms like GitHub, by searching for "Ably" alongside the desired technology. The Ably community resources page sometimes highlights notable community projects, although the primary focus remains on the officially supported SDKs.
When considering a community library, it's advisable to:
- Check the project's activity: Look at recent commits, issue resolution, and pull request merges.
- Examine documentation: Ensure the library is well-documented and provides clear usage instructions.
- Understand its scope: Verify if it covers the specific Ably features required for your application.
- Review dependencies: Be aware of any additional dependencies the library introduces.
For critical applications, relying on an official Ably SDK is generally recommended due to their rigorous testing, active maintenance, and direct support from Ably. The official SDKs are designed to provide robust and reliable connectivity to the Ably platform, ensuring consistent performance and access to the latest features. The Mozilla Developer Network's definition of an SDK emphasizes the comprehensive nature of these tools, which Ably's official offerings aim to embody.