swift-configuration

1.0.1

API package for reading configuration.
apple/swift-configuration

What's New

1.0.1

2026-01-13T13:51:17Z

What's Changed

SemVer Patch

  • Add support for one zero and yes no boolean strings in environement variables provider by @Adobels in #120
  • Update EnvironmentValueArrayDecoder to emit empty values when present by @Adobels in #133

Other Changes

  • Upgrade GitHub Actions for Node 24 compatibility by @salmanmkc in #119
  • Docs: Update KeyMappingProvider example to use prefixKeys(with:) by @sidepelican in #125
  • Update method signatures in code snippets within code comments. by @Adobels in #121
  • Edits for active voice over passive, present tense over past, and a couple of typos. by @heckj in #136
  • [Docs] Link Mattt's TOML provider under Community Providers by @czechboy0 in #129
  • Update example to 1.0 by @czechboy0 in #111
  • [CI] Fix static SDK build workflow by @czechboy0 in #141
  • [Docs] Custom provider guidelines by @czechboy0 in #137
  • switch links from symbol links to reference sources by @heckj in #142
  • bump min service lifecycle dependency to 2.8 by @heckj in #143

New Contributors

Full Changelog: 1.0.0...1.0.1

Swift Configuration

A Swift library for reading configuration in applications and libraries.

Overview

Swift Configuration defines an abstraction layer between configuration readers and providers.

Applications and libraries read configuration through a consistent API, while the actual provider is set up once at the application's entry point.

Examples

Swift Configuration allows you to combine multiple providers in a hierarchy, where values from higher-priority sources override those from lower-priority ones.

For example, if you have a default configuration in JSON:

{
  "http": {
    "timeout": 30
  }
}

And want to be able to provide an override for that using an environment variable:

# Environment variables:
HTTP_TIMEOUT=15

The example code below creates the two relevant providers, and resolves them in the order you list:

let config = ConfigReader(providers: [
    EnvironmentVariablesProvider(),
    try await FileProvider<JSONSnapshot>(filePath: "/etc/config.json")
])
let httpTimeout = config.int(forKey: "http.timeout", default: 60)
print(httpTimeout) // prints 15

The resolved configuration value is 15 from the environment variable. Without the environment variable, it would use 30 from the JSON file. If both sources are unavailable, the fallback default of 60 is returned.

Tip: More example use cases are described in example use cases, and complete working examples are available in the Examples directory.

Quick start

Add the dependency to your Package.swift:

.package(url: "https://github.com/apple/swift-configuration", from: "1.0.0")

Add the library dependency to your target:

.product(name: "Configuration", package: "swift-configuration")

Import and use in your code:

import Configuration

let config = ConfigReader(provider: EnvironmentVariablesProvider())
let httpTimeout = config.int(forKey: "http.timeout", default: 60)
print("The HTTP timeout is: \(httpTimeout)")

Getting started guides

For more, check out the full documentation.

Package traits

This package offers additional integrations you can enable using package traits. To enable an additional trait on the package, update the package dependency:

.package(
    url: "https://github.com/apple/swift-configuration",
    from: "1.0.0",
+   traits: [.defaults, "YAML"]
)

Available traits:

  • JSON (default): Adds support for FileProvider<JSONSnapshot>, a ConfigProvider for reading JSON files.
  • Logging (opt-in): Adds support for AccessLogger, a way to emit access events into a SwiftLog.Logger.
  • Reloading (opt-in): Adds support for auto-reloading variants of file providers, such as ReloadingFileProvider<JSONSnapshot> (when JSON is enabled) and ReloadingFileProvider<YAMLSnapshot> (when YAML is enabled).
  • CommandLineArguments (opt-in): Adds support for CommandLineArgumentsProvider for parsing command line arguments.
  • YAML (opt-in): Adds support for FileProvider<YAMLSnapshot>, a ConfigProvider for reading YAML files.

Supported platforms and minimum versions

The library is supported on Apple platforms and Linux.

Component macOS Linux iOS tvOS watchOS visionOS
Configuration ✅ 15+ ✅ ✅ 18+ ✅ 18+ ✅ 11+ ✅ 2+

Configuration providers

Built-in providers

The library includes comprehensive built-in provider support:

Community providers

You can also implement a custom ConfigProvider for specialized configuration formats and sources.

Key features

Documentation

Comprehensive documentation is hosted on the Swift Package Index.

Description

  • Swift Tools 6.2.0
View More Packages from this Author

Dependencies

Last updated: Sun Feb 01 2026 16:43:52 GMT-1000 (Hawaii-Aleutian Standard Time)