FastAPI service for calculating structured astrological chart data from birth information using Flatlib, Swiss Ephemeris and Docker.
Astrology Chart API is a backend service that receives birth data and returns a structured JSON representation of an astrological chart.
The project was designed as a reusable calculation layer for astrology-based applications, dashboards, automation workflows and AI-assisted interpretation systems.
It focuses on calculation and data structure, not on textual astrological interpretation.
The service receives:
- Birth date
- Birth time
- Birth city
- Timezone
- House system
And returns:
- Sun sign and degree
- Moon sign and degree
- Ascendant sign
- 12 house signs
- Planetary positions
- Retrograde status
- Calculation engine metadata
The calculation engine is powered by Flatlib and Swiss Ephemeris.
Astrology products often mix interface, interpretation text, user data and chart calculation in the same codebase.
This project separates the calculation layer into a small HTTP service so it can be reused by:
- Web applications
- Member platforms
- Admin dashboards
- Personal astrology tools
- Automation workflows
- AI-powered interpretation systems
This makes the astrology calculation layer easier to test, replace, deploy and integrate with different frontends.
Client
↓
FastAPI Route
↓
Pydantic Validation
↓
Geocoding Service
↓
Timezone Conversion
↓
Flatlib / Swiss Ephemeris
↓
Structured JSON Response| Layer | Responsibility |
|---|---|
| FastAPI | HTTP routes and OpenAPI/Swagger documentation |
| Pydantic | Request and response validation |
| Geocoding | Converts city names into latitude/longitude |
| Timezone handling | Converts local birth time to UTC |
| Flatlib / Swiss Ephemeris | Calculates chart objects and positions |
| Tests | Validate endpoint behavior and response shape |
- Python 3.11+
- FastAPI
- Pydantic
- Flatlib
- Swiss Ephemeris
- OpenCage Geocoding API
- Docker / Docker Compose
- Pytest
- GitHub Actions
GET /healthResponse:
{
"ok": true,
"service": "astrology-chart-api"
}POST /chartRequest:
{
"name": "Demo User",
"birth_date": "1990-08-15",
"birth_time": "14:35",
"birth_city": "São Paulo, Brasil",
"timezone": "America/Sao_Paulo",
"house_system": "equal"
}Response excerpt:
{
"name": "Demo User",
"birth_city": "São Paulo, Brasil",
"timezone": "America/Sao_Paulo",
"latitude": -23.5505,
"longitude": -46.6333,
"house_system": "equal",
"sun": "Leo 22.41",
"moon": "Cancer 18.31",
"ascendant": "Sagittarius",
"houses": {
"house_1": "Sagittarius"
},
"planets": {
"sun": {
"sign": "Leo",
"longitude": 142.41,
"sign_degree": 22.41,
"is_retrograde": false
}
},
"engine": "flatlib-swiss-ephemeris"
}Docker is the recommended runtime because Flatlib and Swiss Ephemeris depend on native packages.
cp .env.example .env
docker compose up --buildOpen:
http://localhost:8000/docsRun tests:
docker compose run --rm astrology-chart-api pytestpython -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
pytest
uvicorn app.main:app --reloadOn Unix-like shells, activate the virtual environment with:
source .venv/bin/activateOPENCAGE_API_KEY=your_key_hereFor local testing without an API key, the project includes fallback coordinates for a small set of Brazilian cities.
Fallback cities currently include São Paulo, Florianópolis, Rio de Janeiro, Curitiba, Belo Horizonte, Porto Alegre and Brasília.
Run tests locally:
pytestOr through Docker:
docker compose run --rm astrology-chart-api pytestThe current automated test suite validates the /chart endpoint response shape and the expected chart fields.
- Only the
equalhouse system is currently exposed. - Geocoding depends on OpenCage when the requested city is not available in the local fallback list.
- The service returns structured chart data only; it does not generate astrological interpretation text.
- The project is intended as a reusable calculation service, not as a complete user-facing astrology product.
- The fallback city list is intentionally small and intended for local demos/tests.
Potential next improvements:
- Add support for additional house systems.
- Expand automated tests for validation errors and geocoding fallbacks.
- Add example client requests with
curland Python. - Add optional deployment guide for a hosted API environment.
- Add versioned API routes if the service becomes public-facing.
- API design with FastAPI
- Domain-specific calculation workflows
- Pydantic request/response modeling
- External geocoding integration
- Timezone conversion for user-submitted birth data
- Dockerized Python service deployment
- Automated API testing
- Service-oriented architecture for astrology applications
MIT. See LICENSE.
