A cross-platform Swift library for accessing Yahoo Finance data through their unofficial API.
This is NOT an official Yahoo Finance library
- NOT written, endorsed, or sponsored by Yahoo Inc.
- This library is intended for educational and personal use
- Uses unofficial Yahoo Finance APIs that may change without notice
- Users are solely responsible for compliance with Yahoo's Terms of Service and usage policies
- Use at your own risk and ensure you follow all applicable terms and conditions
- Cross-Platform: Works on Apple platforms (iOS, macOS, watchOS, tvOS) and Linux
- Modern Swift: Built with Swift 6.0+ using async/await and actors
- Flexible Architecture: Pluggable HTTP transport layer via
ClientTransportprotocol - Type Safety: Leverages swift-http-types for safe HTTP handling
- Server Ready: Compatible with Vapor, Hummingbird, and other Swift on Server frameworks
- Comprehensive Error Handling: Detailed error types for different failure scenarios
- Swift 6.0+
- Platforms: iOS 15.0+, macOS 12.0+, watchOS 8.0+, tvOS 13.0+, Linux
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/kubens/swift-yahoo-finance", branch: "main")
]Or add it through Xcode:
- File → Add Package Dependencies
- Enter the repository URL
- Select the version you want to use
import YahooFinance
// Create your transport implementation
let transport = MyClientTransport()
// Initialize YahooFinance
let yahooFinance = YahooFinance(transport: transport)
// Fetch data (example implementation)
let data = try await yahooFinance.perform(request, responseAs: MyDataType.self)The library is built around a few core components:
YahooFinance: Main entry point actor for all operationsClientTransport: Protocol for HTTP transport implementationsYahooFinanceError: Comprehensive error handling
The library provides detailed error information through YahooFinanceError:
authenticationFailed: Authentication issuesinvalidResponse(HTTPResponse.Status): HTTP response errorsnetworkError(Error): Network connectivity problemsdecodingError(Error): Data parsing failures
swift buildswift testswift package generate-documentation- Fork the repository
- Create your feature branch
- Follow coding standards (SRP, DRY, KISS, Apple semantics)
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
This library is not affiliated with, endorsed by, or sponsored by Yahoo Inc. Yahoo Finance is a trademark of Yahoo Inc. Users of this library are responsible for ensuring their usage complies with Yahoo's Terms of Service and any applicable laws and regulations.