Unofficial Appwrite Unity SDK
This SDK is compatible with Appwrite server version 1.7.x.
Appwrite is an open-source backend-as-a-service that abstracts and simplifies complex development tasks behind a simple REST API. The Unity SDK allows you to easily integrate your Unity app with Appwrite, providing access to authentication, databases, storage, real-time features, and more.
Use this SDK to quickly connect your Unity project to Appwrite and interact with all backend APIs and tools. For full API documentation and tutorials, visit: https://appwrite.io/docs
- Open Unity and go to Window > Package Manager
- Click the + button and select Add package from git URL
- Enter the following URL:
https://github.com/fellmonkey/sdk-appwrite-unity.git?path=Assets
- Download the latest release from GitHub or zip
- Import the Unity package into your project
- In Unity, open the Appwrite → Setup Assistant menu and install the required dependencies
This SDK requires the following Unity packages and libraries:
- UniTask: For async/await support in Unity
- NativeWebSocket: For WebSocket real-time subscriptions
- System.Text.Json: For JSON serialization (provided as a DLL in the project)
You can also install UniTask and other required dependencies automatically via Appwrite → Setup Assistant in Unity.
Before you begin
First, create an Appwrite configuration:
— via the QuickStart window in the Appwrite Setup Assistant
— or through the menu Appwrite → Create Configuration
[SerializeField] private AppwriteConfig config;
private AppwriteManager _manager;
private async UniTask ExampleWithManager()
{
// Get or create manager
_manager = AppwriteManager.Instance ?? new GameObject("AppwriteManager").AddComponent<AppwriteManager>();
_manager.SetConfig(config);
// Initialize
var success = await _manager.Initialize();
if (!success) { Debug.LogError("Failed to initialize AppwriteManager"); return; }
// Direct client access
var client = _manager.Client;
var pingResult = await client.Ping();
Debug.Log($"Ping result: {pingResult}");
// Service creation through DI container
var account = _manager.GetService<Account>();
var databases = _manager.GetService<Databases>();
// Realtime example
var realtime = _manager.Realtime;
var subscription = realtime.Subscribe(
new[] { "databases.*.collections.*.documents" },
response => Debug.Log($"Realtime event: {response.Events[0]}")
);
}
[SerializeField] private AppwriteConfig config;
private async UniTask ExampleWithDirectClient()
{
// Create and configure client
var client = new Client()
.SetEndpoint(config.Endpoint)
.SetProject(config.ProjectId);
if (!string.IsNullOrEmpty(config.ApiKey))
client.SetKey(config.ApiKey);
if (!string.IsNullOrEmpty(config.RealtimeEndpoint))
client.SetEndPointRealtime(config.RealtimeEndpoint);
// Test connection
var pingResult = await client.Ping();
Debug.Log($"Direct client ping: {pingResult}");
// Create services manually
var account = new Account(client);
var databases = new Databases(client);
// Realtime example
// You need to create a Realtime instance manually or attach dependently
realtime.Initialize(client);
var subscription = realtime.Subscribe(
new[] { "databases.*.collections.*.documents" },
response => Debug.Log($"Realtime event: {response.Events[0]}")
);
}
try
{
var result = await client..Async();
}
catch (AppwriteException ex)
{
Debug.LogError($"Appwrite Error: {ex.Message}");
Debug.LogError($"Status Code: {ex.Code}");
Debug.LogError($"Response: {ex.Response}");
}
When working with the Databases API in Unity, models should be prepared for serialization using the System.Text.Json library. By default, System.Text.Json converts property names from PascalCase to camelCase when serializing to JSON. If your Appwrite collection attributes are not in camelCase, this can cause errors due to mismatches between serialized property names and actual attribute names in your collection.
To avoid this, add the JsonPropertyName
attribute to each property in your model class to match the attribute name in Appwrite:
public class TestModel
{
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("release_date")]
public DateTime ReleaseDate { get; set; }
}
The JsonPropertyName
attribute ensures your data object is serialized with the correct attribute names for Appwrite databases. This approach works seamlessly in Unity with the included System.Text.Json DLL.
Please see CHANGELOG for more information about recent changes.