Official Swift SDK for AstrologyAPI.com — Vedic & Western astrology calculations, charts, PDF reports, and more, all in idiomatic async/await Swift.
Add the package to your Package.swift:
dependencies: [
.package(url: "https://github.com/astrologyapi/astrologyapi-swift.git", from: "1.0.0")
]Or in Xcode: File → Add Package Dependencies → paste the repo URL.
import AstrologyAPI
// Initialize the client with your API key
let client = AstrologyAPI(
configuration: AstrologyAPIConfiguration(
apiKey: "ak-your-api-key"
)
)
let birthData = BirthData(
day: 10, month: 5, year: 1990,
hour: 19, min: 55,
lat: 19.20, lon: 72.83,
tzone: 5.5 // UTC+5:30 (IST)
)
// Vedic birth chart
let chart = try await client.vedic.getChart(.d1, data: birthData)
// Today's sun-sign horoscope
let horoscope = try await client.horoscopes.getDaily(zodiac: .taurus)
// PDF report with custom branding
let pdf = try await client.pdf.vedic.getProfessionalHoroscope(
birthData,
branding: PDFBranding(companyName: "My App", chartStyle: "north-indian")
)The SDK uses token-based authentication with your AstrologyAPI key.
let config = AstrologyAPIConfiguration(apiKey: "ak-your-key")
let client = AstrologyAPI(configuration: config)Your API key starts with ak- and is passed via the x-astrologyapi-key header.
- 140 endpoints across 11 namespaces — complete API coverage
- async/await throughout — works seamlessly with Swift Concurrency
- Typed errors — catch
AuthenticationError,RateLimitError,QuotaExceededError, etc. - Type-safe enums —
ChartID,ZodiacSign,PlanetName,Language,HouseSystem - PDF reports — binary
Datareturn with optional white-label branding - Automatic retry — exponential back-off for network errors and 5xx responses
- Environment variable support —
ASTROLOGYAPI_API_KEY - Zero dependencies — built on
URLSessionandFoundationonly - Multi-platform — iOS 15+, macOS 12+, watchOS 8+, tvOS 15+
| Namespace | Endpoints | Description |
|---|---|---|
client.vedic |
55 | Birth charts, dashas, doshas, panchang, matchmaking, varshaphal |
client.kp |
6 | Krishnamurti Paddhati system |
client.lalKitab |
5 | Lal Kitab horoscope, debts, remedies |
client.horoscopes |
8 | Daily / weekly / monthly sun-sign & nakshatra predictions |
client.numerology |
17 | Vedic numerology + Western numerological calculations |
client.western |
30 | Tropical birth charts, solar return, synastry, personality |
client.westernTransit |
5 | Tropical & natal transit calculations |
client.tarot |
2 | Tarot predictions and yes/no readings |
client.chinese |
2 | Chinese zodiac and year forecast |
client.pdf |
8 | All PDF reports (Vedic + Western) with white-label branding |
client.location |
2 | Geo search and timezone/DST lookup |
let config = AstrologyAPIConfiguration(
apiKey: "ak-your-key", // Required
language: .hindi, // Optional: localise interpretation text
pdfBranding: PDFBranding( // Optional: applied to all PDF calls
companyName: "My Astro App",
logoUrl: "https://example.com/logo.png",
chartStyle: "north-indian"
),
maxRetries: 3 // Default: 3 retries with exponential back-off
)
let client = AstrologyAPI(configuration: config)en · hi · te · ta · ml · kn · mr · bn · gu · or · pa
let data = BirthData(
day: 10, month: 5, year: 1990,
hour: 19, min: 55,
lat: 19.20, // latitude
lon: 72.83, // longitude
tzone: 5.5 // UTC offset (e.g. 5.5 for IST, -5.0 for EST)
)let match = MatchData(male: maleData, female: femaleData)
let report = try await client.vedic.getDetailedMatchReport(match)let numero = NumeroData(day: 10, month: 5, year: 1990, name: "John Doe")
let lifePath = try await client.numerology.getLifepathNumber(numero)let branding = PDFBranding(
logoUrl: "https://yourapp.com/logo.png",
companyName: "Your Company",
chartStyle: "north-indian" // or "south-indian" / "east-indian"
)// Divisional charts
let d1 = try await client.vedic.getChart(.d1, data: birthData) // Rasi
let d9 = try await client.vedic.getChart(.d9, data: birthData) // Navamsa
let d10 = try await client.vedic.getChart(.d10, data: birthData) // Dashamsa
// Vimshottari Dasha
let currentDasha = try await client.vedic.getCurrentDasha(birthData)
let majorDashas = try await client.vedic.getMajorDasha(birthData)
// Doshas
let kalsarpa = try await client.vedic.getKalsarpaDosha(birthData)
let sadhesati = try await client.vedic.getSadhesatiStatus(birthData)
let pitraDosha = try await client.vedic.getPitraDosha(birthData)
// Remedies
let gems = try await client.vedic.getGemSuggestion(birthData)
let rudraksha = try await client.vedic.getRudrakshaSuggestion(birthData)
// Panchang
let panchang = try await client.vedic.getBasicPanchang(birthData)
let muhurta = try await client.vedic.getHoraMuhurta(birthData)
// Reports
let ascendant = try await client.vedic.getAscendantReport(birthData)
let houseReport = try await client.vedic.getHouseReport(planet: .saturn, data: birthData)// Charts
let planets = try await client.western.getPlanets(birthData)
let cusps = try await client.western.getHouseCusps(system: .placidus, data: birthData)
let aspects = try await client.western.getAspects(birthData)
// Solar return
let solar = try await client.western.getSolarReturnDetails(birthData)
// Personality
let personality = try await client.western.getPersonality(birthData)
let karmaReport = try await client.western.getKarmaDestiny(birthData)
// Synastry
let couple = CoupleBirthData(person1: birthData, person2: partnerData)
let synastry = try await client.western.getSynastry(couple)
// Transits
let transits = try await client.westernTransit.getDaily(birthData)
// Compatibility
let compat = try await client.western.getZodiacCompatibility(zodiac: .taurus, partner: .scorpio)// Vedic PDFs
let miniKundli = try await client.pdf.vedic.getMiniKundli(birthData)
let basicPDF = try await client.pdf.vedic.getBasicHoroscope(birthData)
let proPDF = try await client.pdf.vedic.getProfessionalHoroscope(birthData, branding: branding)
let matchPDF = try await client.pdf.vedic.getMatchMaking(matchData)
// Western PDFs
let natalPDF = try await client.pdf.western.getNatalChart(birthData)
let forecastPDF = try await client.pdf.western.getLifeForecast(birthData)
let solarPDF = try await client.pdf.western.getSolarReturn(birthData)
let synastryPDF = try await client.pdf.western.getSynastry(coupleData)
// Save to disk (macOS/iOS)
try pdfData.write(to: URL(fileURLWithPath: "/tmp/kundli.pdf"))The SDK maps every HTTP error to a specific typed case:
do {
let chart = try await client.vedic.getChart(.d1, data: birthData)
} catch let error as AstrologyAPIError {
switch error {
case .authenticationError(let msg, _):
print("Invalid API key:", msg)
case .rateLimitError(let msg, _, let retryAfter):
print("Rate limited. Retry in \(retryAfter ?? 60)s:", msg)
case .quotaExceededError(let msg, _):
print("Monthly quota exhausted:", msg)
case .planRestrictedError(let msg, _):
print("Endpoint not on your plan:", msg)
case .validationError(let msg, _, _):
print("Invalid parameters:", msg)
case .networkError(let msg, let underlying):
print("Network error:", msg, underlying)
case .serverError(let msg, let code, _):
print("Server error \(code):", msg)
default:
print("Error:", error.localizedDescription)
}
}Call any endpoint not yet in a typed namespace:
let rawData = try await client.customRequest(
endpoint: "some_new_endpoint",
body: BirthData(...)
)| Platform | Minimum version |
|---|---|
| iOS | 15.0+ |
| macOS | 12.0+ |
| watchOS | 8.0+ |
| tvOS | 15.0+ |
| Swift | 5.9+ |
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Add tests for any new behaviour
- Run
swift test— all tests must pass - Open a Pull Request
MIT — see LICENSE.
Official Swift SDK — built and maintained by AstrologyAPI.com