For AI agents: the documentation index is at llms.txt. Guide pages have a markdown version at the same path with .md appended, before any query string or fragment.
Create a SupabaseClient with your Project URL and your publishable key. You can find them in your project's Project Settings → API Keys. The Supabase client is your entrypoint to the rest of the Supabase functionality and is the easiest way to interact with everything we offer within the Supabase ecosystem.
The initializer throws a SupabaseClientError when the URL has no scheme or no host, so call it with try. Create the client once and share it: it holds the session and the Realtime connection.
SupabaseClient.Configuration. It has one group for each module (database, auth, functions, realtime, storage) and a global group for all of them.import Supabase
let supabase = try SupabaseClient(
supabaseURL: URL(string: "https://xyzcompany.supabase.co")!,
supabaseKey: "your-publishable-key"
)
import Supabase
let supabase = try SupabaseClient(
supabaseURL: URL(string: "https://xyzcompany.supabase.co")!,
supabaseKey: "your-publishable-key",
configuration: SupabaseClient.Configuration(
database: .init(
schema: "public"
),
auth: .init(
storage: MyCustomAuthStorage() // conforms to AuthStorage
),
global: .init(
headers: [HTTPField.Name("x-my-custom-header")!: "my-app-name"],
http: .init(transport: URLSessionTransport(session: URLSession.myCustomSession))
)
)
)
import Supabase
let supabase = try SupabaseClient(
supabaseURL: URL(string: "https://xyzcompany.supabase.co")!,
supabaseKey: "your-publishable-key",
configuration: SupabaseClient.Configuration(
database: .init(
// Disable automatic retries for this client
retryEnabled: false
)
)
)
import Logging
import Supabase
var logger = Logger(label: "com.example.app")
logger.logLevel = .debug
let supabase = try SupabaseClient(
supabaseURL: URL(string: "https://xyzcompany.supabase.co")!,
supabaseKey: "your-publishable-key",
configuration: SupabaseClient.Configuration(
global: .init(
logger: logger
)
)
)
import Supabase
struct AppVersionMiddleware: ClientMiddleware {
func intercept(
_ request: HTTPRequest,
body: HTTPBody?,
next: nonisolated(nonsending) @Sendable (HTTPRequest, HTTPBody?) async throws
-> (HTTPResponse, HTTPBody?)
) async throws -> (HTTPResponse, HTTPBody?) {
var request = request
request.headerFields[HTTPField.Name("X-App-Version")!] = "2.1.0"
return try await next(request, body)
}
}
let supabase = try SupabaseClient(
supabaseURL: URL(string: "https://xyzcompany.supabase.co")!,
supabaseKey: "your-publishable-key",
configuration: SupabaseClient.Configuration(
global: .init(
http: .init(
transport: URLSessionTransport(session: URLSession.myCustomSession),
middlewares: [AppVersionMiddleware()],
timeout: .seconds(30)
)
)
)
)
import Supabase
let supabase = try SupabaseClient(
supabaseURL: URL(string: "https://xyzcompany.supabase.co")!,
supabaseKey: "your-publishable-key",
configuration: SupabaseClient.Configuration(
database: .init(
// Provide a custom schema. Defaults to "public".
schema: "other_schema"
)
)
)
// Package.swift
.package(
url: "https://github.com/supabase/supabase-swift.git",
from: "3.0.0-alpha.2",
traits: ["OpenTelemetry"]
)