This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Python client library (SDK) for the Astrology API v3. Provides typed wrappers around 150+ endpoints organized into 16 category clients. Built on httpx (sync HTTP) and pydantic v2 (request/response models). Requires Python 3.10+.
# Install (editable + dev deps)
pip install -e ".[dev]"
# Run all tests (coverage is enforced at 100% branch via addopts)
pytest
# Run a single test file
pytest tests/unit/test_client.py
# Run a single test
pytest tests/unit/test_client.py::TestAstrologyClient::test_client_creation_with_config
# Lint and format
ruff check src/ tests/
ruff format src/ tests/
# Type check (strict mode)
mypy src/astroapi
# Pre-commit hooks
pre-commit installEntry point: AstrologyClient (client.py) — creates an HttpClient and instantiates all 16 category clients. Supports context manager protocol for cleanup.
HTTP layer: HttpClient (utils/http_client.py) wraps httpx.Client with Bearer auth, configurable retry logic (RetryConfig), and response envelope unwrapping (data or result keys). Categories depend on the HttpHelper ABC (utils/http.py), not HttpClient directly.
Categories (categories/): 16 clients inheriting BaseCategoryClient. Each declares an API_PREFIX and builds URLs via _build_url(*segments). InsightsClient is unique — it composes 5 sub-clients (relationship, pet, wellness, financial, business) as instance attributes.
Types (types/):
config.py—AstrologyClientConfig,RetryConfigdataclasses, type aliases, validation constantsrequests.py— Pydantic request models withConfigDict(extra="forbid"), serialized viamodel_dump(exclude_none=True)responses.py— Pydantic response models withextra="allow"(tolerant of API additions)
Validation: Every category method validates inputs via functions in utils/validators.py before making HTTP calls. All errors surface as AstrologyError (errors.py).
Config: API key resolved from AstrologyClientConfig.api_key or env var ASTROLOGY_API_KEY. Also reads ASTROLOGY_API_BASE_URL and ASTROLOGY_DEBUG.
Version is derived automatically from git tags via hatch-vcs (configured in pyproject.toml). There is no hardcoded version anywhere — src/astroapi/_version.py is generated at build/install time.
- Tag
v1.2.3→ package version1.2.3 - Between tags → dev version like
1.2.4.dev3+g<hash> _version.pyis in.gitignore— never commit it
Release flow: create and push a tag, release.yml handles the rest:
git tag v1.2.0
git push origin v1.2.0CI workflows use fetch-depth: 0 in checkout so git tags are always available for version resolution.
- Every source file uses
from __future__ import annotations - Line length: 100 chars
- Double quotes, space indent
- All request models forbid extra fields; all response models allow them
- Tests mock HTTP via
pytest-httpx(httpx_mockfixture). Shared fixtures in tests/conftest.py, mock payloads in tests/mocks/responses.py - Coverage excludes
__init__.pyre-export files andTYPE_CHECKINGblocks