A Swift package providing a type-safe client for the DeepL API, generated from the official OpenAPI specification using swift-openapi-generator.
- Swift 5.9+ / Xcode 15+
Add the package to your Package.swift:
.package(url: "https://github.com/atacan/DeepLAPI", branch: "main"),Then add the dependency to your target. Use DeepLAPI for the full client, or DeepLAPITypes if you only need the types (no networking dependency):
.target(
name: "MyTarget",
dependencies: [
.product(name: "DeepLAPI", package: "DeepLAPI"),
]
),Get your API key from deepl.com/account. Free-tier keys end with :fx and use a different base URL than Pro keys — see the client example below.
import DeepLAPI
import DeepLAPITypes
import OpenAPIAsyncHTTPClient
let apiKey = "your_key_here"
let isFree = apiKey.hasSuffix(":fx")
let serverURL = try isFree ? Servers.Server2.url() : Servers.Server1.url()
let client = Client(
serverURL: serverURL,
transport: AsyncHTTPClientTransport(),
middlewares: [AuthenticationMiddleware(apiKey: "DeepL-Auth-Key \(apiKey)")]
)
// Translate text
let response = try await client.translateText(
body: .json(.init(
text: ["Hello, world!"],
source_lang: .EN,
target_lang: .DE
))
)
let translations = try response.ok.body.json.translationsAll request and response types map directly to the DeepL API reference. Use Xcode autocomplete or browse Types.swift to discover available parameters.
| Package | Role |
|---|---|
| swift-openapi-runtime | Runtime support for the generated client |
| swift-openapi-async-http-client | AsyncHTTPClient-backed transport |