atacan/DeepLAPI
Type-safe Swift client for the DeepL API, generated from the official OpenAPI specification
Requirements
- Swift 5.9+ / Xcode 15+
Installation
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"),
]
),API Key
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.
Using the Client
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.
Dependencies
| Package | Role | |---|---| | swift-openapi-runtime | Runtime support for the generated client | | swift-openapi-async-http-client | AsyncHTTPClient-backed transport |
Package Metadata
Repository: atacan/DeepLAPI
Stars: 0
Forks: 0
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: deepl, openapi, swift, swift-openapi-generator, swift-package, translation
README: README.md