Metadata-Version: 2.4
Name: cosmicephemeris-client
Version: 0.3.1
Summary: Synchronous Python client for the Cosmic Ephemeris calculation gateway
Author-email: Cosmic Ephemeris <support@cosmicephemeris.com>
Maintainer-email: Cosmic Ephemeris <support@cosmicephemeris.com>
License-Expression: ISC
Project-URL: Homepage, https://cosmicephemeris.com
Project-URL: Documentation, https://cosmicephemeris.com/docs-developer-platform.html
Project-URL: Support, https://cosmicephemeris.com/contact.html
Keywords: astrology,astronomy,ephemeris,api,sdk
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Provides-Extra: receipts
Requires-Dist: cryptography<48,>=42; extra == "receipts"
Dynamic: license-file

# Cosmic Ephemeris Python SDK

The official synchronous Python client for the Cosmic Ephemeris calculation API.

- 78 calculation methods
- Python 3.10 or newer
- Typed inputs and route-specific response envelopes
- No required runtime dependencies
- Bounded transport concurrency, responses, and deadlines
- Sanitized errors and no automatic retries

## Install

```sh
python -m pip install cosmicephemeris-client
```

Optional signed-receipt verification uses `cryptography`:

```sh
python -m pip install "cosmicephemeris-client[receipts]"
```

## Quick start

```python
from cosmicephemeris_client import (
    CosmicEphemerisClient,
    HTTPError,
    RequestTimeoutError,
)

client = CosmicEphemerisClient()  # Reads COSMICEPHEMERIS_KEY.

try:
    result = client.birth_chart({
        "date": "1990-01-01",
        "time": "12:00",
        "timezone": "America/New_York",
        "lat": 40.7128,
        "lon": -74.006,
    })
    print(result["chart"]["planets"]["Sun"])
except HTTPError as error:
    print(error.status, error.retry_after)
except RequestTimeoutError:
    print("The deadline expired; admitted work may still consume quota.")
```

You may pass `api_key=` explicitly. An explicit key takes precedence over
`COSMICEPHEMERIS_KEY`.

API keys are server credentials. Never put them in browser code, mobile applications,
URLs, public environment variables, analytics, notebooks intended for sharing, or
source control.

## Methods and typing

Methods use Python snake case and map directly to the documented REST operations.
They return the complete response dictionary without changing its envelope.

The package is marked with `py.typed`. Every public method has a documented input
`TypedDict` and a route-specific response type derived from the maintained OpenAPI
contract. Selected complex responses have additional hand-maintained nested types.

Common groups include:

- Natal charts, houses, aspects, transits, synastry, composite, and Davison charts
- Vedic Vargas, Vimshottari, Panchang, Ashtakoota, and Ashtakavarga
- Moon phases, planetary events, aspect windows, eclipses, and event calendars
- SVG, PNG, reports, and structured export formats
- Place search, timezone resolution, relocation, and astrocartography
- Convention, uncertainty, robustness, and electional audit operations

See the [complete developer documentation](https://cosmicephemeris.com/docs-developer-platform.html)
for every method, request field, quota rule, and response example.

## Transport and deadlines

The client:

- Validates the API key and documented input boundaries before transport.
- Uses verified HTTPS and sends credentials only to the configured origin.
- Ignores proxy environment variables, cookies, and redirects.
- Allows HTTP only through explicit loopback-only test configuration.
- Bounds request size, response size, and outstanding transport workers.
- Rejects compressed, malformed, truncated, duplicate-key, and non-finite JSON.
- Does not retry automatically.

Default deadlines vary by operation. They can be bounded with `timeout=`,
`planetary_events_timeout=`, and `timeline_timeout=` when constructing the
client. A timeout may still consume quota if the gateway already accepted the work.

## Errors

Errors expose only safe structured information. They do not include API keys,
request payloads, response bodies, raw headers, URLs, or underlying transport
exception details.

The primary classes are:

- `ValidationError`
- `HTTPError`
- `RequestTimeoutError`
- `ClientBusyError`
- `TransportError`
- `ResponseError`

## Signed calculation receipts

```python
from cosmicephemeris_client import verify_calculation_receipt

valid = verify_calculation_receipt(response, public_jwk)
```

Receipt verification requires the optional `receipts` dependency. It checks the
Ed25519 signature and canonical hashes. It proves response integrity and service
provenance; it does not independently validate the meaning or correctness of a
calculation.

## Local verification

From `clients/python`:

```sh
python scripts/generate_response_types.py --check
PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=src python -m unittest discover -s tests -v
python -m build
```

Tests use synthetic credentials and local HTTP/TLS servers. They do not call the
production API unless an example is deliberately run with a real key.

## Support and license

- Documentation: https://cosmicephemeris.com/docs-developer-platform.html
- Support: support@cosmicephemeris.com
- License: ISC
