-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
149 lines (128 loc) · 6.26 KB
/
client.py
File metadata and controls
149 lines (128 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""Main Astrology API client."""
from __future__ import annotations
from typing import Any
from astroapi.categories.analysis import AnalysisClient
from astroapi.categories.astrocartography import AstrocartographyClient
from astroapi.categories.charts import ChartsClient
from astroapi.categories.chinese import ChineseClient
from astroapi.categories.data import DataClient
from astroapi.categories.eclipses import EclipsesClient
from astroapi.categories.enhanced import EnhancedClient
from astroapi.categories.fengshui import FengshuiClient
from astroapi.categories.fixed_stars import FixedStarsClient
from astroapi.categories.glossary import GlossaryClient
from astroapi.categories.horary import HoraryClient
from astroapi.categories.horoscope import HoroscopeClient
from astroapi.categories.human_design import HumanDesignClient
from astroapi.categories.insights import InsightsClient
from astroapi.categories.kabbalah import KabbalahClient
from astroapi.categories.lunar import LunarClient
from astroapi.categories.numerology import NumerologyClient
from astroapi.categories.palmistry import PalmistryClient
from astroapi.categories.pdf import PdfClient
from astroapi.categories.render import RenderClient
from astroapi.categories.svg import SvgClient
from astroapi.categories.tarot import TarotClient
from astroapi.categories.traditional import TraditionalClient
from astroapi.categories.vedic import VedicClient
from astroapi.categories.ziwei import ZiweiClient
from astroapi.types.config import AstrologyClientConfig
from astroapi.utils.http import HttpxHttpHelper
from astroapi.utils.http_client import HttpClient
class AstrologyClient:
"""Main entry point for the Astrology API client.
Provides access to all API endpoints through category-specific sub-clients.
Example:
```python
from astroapi import AstrologyClient, Subject, BirthData
# Initialize client (uses ASTROLOGY_API_KEY environment variable)
client = AstrologyClient()
# Or provide API key directly
from astroapi.types import AstrologyClientConfig
config = AstrologyClientConfig(api_key="your_api_key")
client = AstrologyClient(config)
# Get planetary positions
subject = Subject(birth_data=BirthData(
year=1990, month=1, day=1, hour=12, minute=0
))
positions = client.data.get_positions(subject)
# Use context manager for automatic cleanup
with AstrologyClient() as client:
chart = client.charts.get_natal_chart(subject)
```
Attributes:
data: Data client for planetary positions and related data
charts: Charts client for natal, synastry, composite, transit charts
horoscope: Horoscope client for personalized and sun sign horoscopes
analysis: Analysis client for interpretations and reports
glossary: Glossary client for reference data
astrocartography: Astrocartography client for location mapping
chinese: Chinese astrology client (BaZi, zodiac signs)
eclipses: Eclipses client for eclipse calculations
lunar: Lunar client for moon phases and related data
numerology: Numerology client for numerology calculations
tarot: Tarot client for card draws and readings
traditional: Traditional astrology client (dignities, receptions)
fixed_stars: Fixed stars client for star positions and conjunctions
insights: Insights client with specialized sub-clients
render: Render client for chart image rendering
fengshui: Feng Shui client for flying stars
horary: Horary client for question charts
human_design: Human Design client for bodygraph calculations
kabbalah: Kabbalah client for Tree of Life
palmistry: Palmistry client for palm analysis
pdf: PDF client for report generation
vedic: Vedic astrology client
ziwei: Zi Wei Dou Shu client
svg: SVG client for chart rendering (deprecated, use render)
enhanced: Enhanced client for advanced calculations
"""
def __init__(self, config: AstrologyClientConfig | None = None) -> None:
"""Initialize Astrology API client.
Args:
config: Client configuration (if None, uses defaults with ASTROLOGY_API_KEY env var)
"""
self.config = config or AstrologyClientConfig()
# Initialize HTTP layer
http_client = HttpClient(self.config)
http_helper = HttpxHttpHelper(http_client)
# Initialize all category clients
self.data = DataClient(http_helper)
self.charts = ChartsClient(http_helper)
self.horoscope = HoroscopeClient(http_helper)
self.analysis = AnalysisClient(http_helper)
self.glossary = GlossaryClient(http_helper)
self.astrocartography = AstrocartographyClient(http_helper)
self.chinese = ChineseClient(http_helper)
self.eclipses = EclipsesClient(http_helper)
self.lunar = LunarClient(http_helper)
self.numerology = NumerologyClient(http_helper)
self.tarot = TarotClient(http_helper)
self.traditional = TraditionalClient(http_helper)
self.fixed_stars = FixedStarsClient(http_helper)
self.insights = InsightsClient(http_helper)
self.render = RenderClient(http_helper)
self.fengshui = FengshuiClient(http_helper)
self.horary = HoraryClient(http_helper)
self.human_design = HumanDesignClient(http_helper)
self.kabbalah = KabbalahClient(http_helper)
self.palmistry = PalmistryClient(http_helper)
self.pdf = PdfClient(http_helper)
self.vedic = VedicClient(http_helper)
self.ziwei = ZiweiClient(http_helper)
self.svg = SvgClient(http_helper)
self.enhanced = EnhancedClient(http_helper)
# Store HTTP client for cleanup
self._http_client = http_client
def close(self) -> None:
"""Close HTTP client and release resources.
Should be called when the client is no longer needed.
Alternatively, use the client as a context manager.
"""
self._http_client.close()
def __enter__(self) -> AstrologyClient:
"""Enter context manager."""
return self
def __exit__(self, *args: Any) -> None:
"""Exit context manager and cleanup resources."""
self.close()