apple/swift-temporal-sdk
Swift SDK for Temporal
π Overview
The Temporal Swift SDK provides a package for building distributed, durable workflows and activities using Swift's modern concurrency features. Temporal enables you to build reliable applications that recover from failures, scale dynamically, and maintain long-running business processes with confidence.
Key Features:
- π Durable Workflows: Build fault-tolerant workflows that survive
infrastructure failures
- ποΈ Scalable Architecture: Distribute workflow execution across multiple
workers
- β‘ Swift Concurrency: Native integration with Swift Structured Concurrency
- π― Type Safety: Compile-time type checking for workflow and activity
definitions, with struct-based workflows providing additional safety guarantees (queries can't mutate state, validators can't mutate state)
- π Observability: Built-in support for logging, metrics and tracing
- π§ Macro-based APIs: Simple
@Workflowand@Activitymacros to avoid
boilerplate
- π§ͺ Testing Support: Easily test your workflows and activities
βοΈ Use Cases
The Temporal Swift SDK excels in scenarios requiring reliable, long-running business processes such as:
π E-commerce & Payment Processing
- Order fulfillment workflows with inventory, payment, and shipping coordination
- Multi-step payment processing with automatic retry and rollback capabilities
- Subscription billing and recurring payment management
π Data Processing & ETL
- Large-scale data transformation pipelines with fault tolerance
- Event-driven data processing with guaranteed delivery
- Batch processing jobs with progress tracking and resumption
π’ Business Process Automation
- Approval workflows with human-in-the-loop interactions
- Multi-system integration and orchestration
- Document processing and compliance workflows
π Monitoring & Operations
- Health check orchestration across distributed systems
- Automated incident response and remediation
- Scheduled maintenance and cleanup tasks
π Getting Started
Prerequisites
- Swift version: Swift 6.2+
To install/upgrade Swift, see https://www.swift.org/install/
Adding as a dependency
To use the Swift Temporal SDK in your Swift project, add it as a dependency in your Package.swift file:
dependencies: [
.package(url: "https://github.com/apple/swift-temporal-sdk.git", .upToNextMinor(from: "0.6.0"))
]Running the project
- Clone the repository
``bash git clone git@github.com:apple/swift-temporal-sdk.git ``
- Build the package
``bash swift build ``
- Run tests
``bash swift test ``
- Run an example
``bash # Install Temporal CLI from https://temporal.io/setup/install-temporal-cli temporal server start-dev cd Examples/Greeting swift run GreetingExample ``
Usage
Here's a simple example showing how to create a workflow and activity:
import GRPCNIOTransportHTTP2Posix
import Logging
import Temporal
// Define an activity
@ActivityContainer
struct GreetingActivities {
@Activity
func sayHello(input: String) -> String {
"Hello, \(input)!"
}
}
// Define a workflow
@Workflow
struct GreetingWorkflow {
mutating func run(context: WorkflowContext<Self>, input: String) async throws -> String {
let greeting = try await context.executeActivity(
GreetingActivities.Activities.SayHello.self,
options: ActivityOptions(startToCloseTimeout: .seconds(30)),
input: input
)
return greeting
}
}
// Create worker and client
@main
struct MyApp {
static func main() async throws {
let worker = try TemporalWorker(
configuration: .init(
namespace: "default",
taskQueue: "greeting-queue",
instrumentation: .init(serverHostname: "127.0.0.1")
),
target: .ipv4(address: "127.0.0.1", port: 7233),
transportSecurity: .plaintext,
activityContainers: GreetingActivities(),
workflows: [GreetingWorkflow.self],
logger: Logger(label: "worker")
)
let client = try TemporalClient(
target: .ipv4(address: "127.0.0.1", port: 7233),
transportSecurity: .plaintext,
configuration: .init(instrumentation: .init(serverHostname: "127.0.0.1")),
logger: Logger(label: "client")
)
try await withThrowingTaskGroup { group in
group.addTask {
try await worker.run()
}
group.addTask {
try await client.run()
}
// Wait for the worker and client to run
try await Task.sleep(for: .seconds(1))
// Execute workflow
print("Executing workflow")
let result = try await client.executeWorkflow(
type: GreetingWorkflow.self,
options: .init(id: "greeting-1", taskQueue: "greeting-queue"),
input: "World"
)
print(result) // "Hello, World!"
// Cancel the client and worker
group.cancelAll()
}
}
}π Documentation
- API Documentation - Complete
API reference and guides
- Sample projects demonstrating various features
π§° Release Info
[!NOTE] This SDK is currently under active development.
- Release Cadence: Ad-hoc whenever changes land on
main - Version Compatibility: Swift 6.2+ and macOS 15.0+ only
π οΈ Support
If you have any questions or need help, feel free to reach out by opening an issue.
Package Metadata
Repository: apple/swift-temporal-sdk
Stars: 218
Forks: 21
Open issues: 16
Default branch: main
Primary language: swift
License: MIT
README: README.md