aetherx-oracle 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aetherx/__init__.py
ADDED
aetherx/client.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Aether-X Port Congestion Oracle - Python SDK client."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
DEFAULT_RAPIDAPI_HOST = "aether-x-port-congestion-oracle.p.rapidapi.com"
|
|
10
|
+
RISK_ENDPOINT = "/v1/port-risk"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PortRisk(BaseModel):
|
|
14
|
+
"""Predictive congestion signal for a single port."""
|
|
15
|
+
|
|
16
|
+
port_id: str = Field(..., description="UN/LOCODE do porto (ex: BRSSZ)")
|
|
17
|
+
port_name: str = Field(..., description="Nome do porto")
|
|
18
|
+
country: str = Field(..., description="País do porto")
|
|
19
|
+
congestion_score: float = Field(..., description="Score de congestão (0.0 a 1.0)")
|
|
20
|
+
eta_delay_days: float = Field(..., description="Atraso estimado de ETA em dias")
|
|
21
|
+
waiting_vessels: int = Field(..., description="Navios aguardando/ancorados")
|
|
22
|
+
freight_volatility_index: float = Field(..., description="Índice de volatilidade de frete")
|
|
23
|
+
updated_at: str = Field(..., description="Timestamp da última atualização")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class OracleClient:
|
|
27
|
+
"""Cliente para a API Aether-X Port Congestion Oracle (via RapidAPI).
|
|
28
|
+
|
|
29
|
+
Exemplo:
|
|
30
|
+
>>> from aetherx import OracleClient
|
|
31
|
+
>>> client = OracleClient(api_key="SUA_RAPIDAPI_KEY")
|
|
32
|
+
>>> risk = client.get_port_risk("BRSSZ")
|
|
33
|
+
>>> print(risk.congestion_score, risk.waiting_vessels)
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
api_key: str,
|
|
39
|
+
host: str = DEFAULT_RAPIDAPI_HOST,
|
|
40
|
+
base_url: Optional[str] = None,
|
|
41
|
+
timeout: float = 30.0,
|
|
42
|
+
) -> None:
|
|
43
|
+
if not api_key:
|
|
44
|
+
raise ValueError("api_key é obrigatória (sua chave da RapidAPI).")
|
|
45
|
+
|
|
46
|
+
self.api_key = api_key
|
|
47
|
+
self.host = host
|
|
48
|
+
self.base_url = (base_url or f"https://{host}").rstrip("/")
|
|
49
|
+
self.timeout = timeout
|
|
50
|
+
|
|
51
|
+
def get_port_risk(self, port_id: str) -> PortRisk:
|
|
52
|
+
"""Retorna o sinal preditivo de congestão para um porto.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
port_id: Código UN/LOCODE do porto (ex: "BRSSZ", "CNSHA").
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
PortRisk com acesso direto via atributo.
|
|
59
|
+
|
|
60
|
+
Raises:
|
|
61
|
+
ValueError: se port_id for vazio.
|
|
62
|
+
requests.HTTPError: se a API retornar um status de erro.
|
|
63
|
+
"""
|
|
64
|
+
url, headers, params = self._build_request(port_id)
|
|
65
|
+
response = requests.get(
|
|
66
|
+
url, headers=headers, params=params, timeout=self.timeout
|
|
67
|
+
)
|
|
68
|
+
response.raise_for_status()
|
|
69
|
+
return PortRisk.model_validate(response.json())
|
|
70
|
+
|
|
71
|
+
async def get_port_risk_async(self, port_id: str) -> PortRisk:
|
|
72
|
+
"""Versão assíncrona de :meth:`get_port_risk` (requer o extra ``async``).
|
|
73
|
+
|
|
74
|
+
Uso:
|
|
75
|
+
>>> import asyncio
|
|
76
|
+
>>> client = OracleClient(api_key="SUA_RAPIDAPI_KEY")
|
|
77
|
+
>>> risk = asyncio.run(client.get_port_risk_async("BRSSZ"))
|
|
78
|
+
|
|
79
|
+
Instale com: ``pip install aetherx-oracle[async]``
|
|
80
|
+
"""
|
|
81
|
+
try:
|
|
82
|
+
import httpx
|
|
83
|
+
except ImportError as exc: # pragma: no cover - depende do ambiente
|
|
84
|
+
raise ImportError(
|
|
85
|
+
"httpx é necessário para métodos assíncronos. "
|
|
86
|
+
"Instale com: pip install aetherx-oracle[async]"
|
|
87
|
+
) from exc
|
|
88
|
+
|
|
89
|
+
url, headers, params = self._build_request(port_id)
|
|
90
|
+
async with httpx.AsyncClient(timeout=self.timeout) as client:
|
|
91
|
+
response = await client.get(url, headers=headers, params=params)
|
|
92
|
+
response.raise_for_status()
|
|
93
|
+
return PortRisk.model_validate(response.json())
|
|
94
|
+
|
|
95
|
+
async def get_ports_risk_async(self, port_ids: List[str]) -> List[PortRisk]:
|
|
96
|
+
"""Consulta vários portos em paralelo via ``asyncio.gather``.
|
|
97
|
+
|
|
98
|
+
Ideal para fundos quantitativos e bots que monitoram uma carteira de portos.
|
|
99
|
+
"""
|
|
100
|
+
if not port_ids:
|
|
101
|
+
return []
|
|
102
|
+
return list(
|
|
103
|
+
await asyncio.gather(
|
|
104
|
+
*(self.get_port_risk_async(port_id) for port_id in port_ids)
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
def _build_request(self, port_id: str):
|
|
109
|
+
if not port_id:
|
|
110
|
+
raise ValueError("port_id é obrigatório (ex: 'BRSSZ').")
|
|
111
|
+
|
|
112
|
+
url = f"{self.base_url}{RISK_ENDPOINT}"
|
|
113
|
+
headers = {
|
|
114
|
+
"x-rapidapi-key": self.api_key,
|
|
115
|
+
"x-rapidapi-host": self.host,
|
|
116
|
+
}
|
|
117
|
+
params = {"port_id": port_id}
|
|
118
|
+
return url, headers, params
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aetherx-oracle
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Python SDK for the Aether-X Port Congestion Oracle API
|
|
5
|
+
Author: Aether-X Oracle Engine
|
|
6
|
+
License: Proprietary - Machine-to-Machine Data Distribution
|
|
7
|
+
Project-URL: Homepage, https://aether-x-oracle-production.up.railway.app
|
|
8
|
+
Project-URL: Documentation, https://aether-x-oracle-production.up.railway.app/docs
|
|
9
|
+
Project-URL: Terms, https://aether-x-oracle-production.up.railway.app/terms
|
|
10
|
+
Keywords: port,congestion,oracle,logistics,shipping,quant,freight
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: requests>=2.25.0
|
|
14
|
+
Requires-Dist: pydantic>=2.0.0
|
|
15
|
+
Provides-Extra: async
|
|
16
|
+
Requires-Dist: httpx>=0.24.0; extra == "async"
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: pytest>=7.0; extra == "test"
|
|
19
|
+
Requires-Dist: responses>=0.23; extra == "test"
|
|
20
|
+
Requires-Dist: httpx>=0.24.0; extra == "test"
|
|
21
|
+
|
|
22
|
+
# aetherx-oracle
|
|
23
|
+
|
|
24
|
+
SDK Python oficial para a **Aether-X Port Congestion Oracle API** — sinais preditivos de congestão portuária, atraso de ETA e volatilidade de frete para portos globais.
|
|
25
|
+
|
|
26
|
+
## Instalação
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install aetherx-oracle
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Uso rápido
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from aetherx import OracleClient
|
|
36
|
+
|
|
37
|
+
client = OracleClient(api_key="SUA_RAPIDAPI_KEY")
|
|
38
|
+
|
|
39
|
+
risk = client.get_port_risk("BRSSZ")
|
|
40
|
+
|
|
41
|
+
print(risk.port_name) # Santos
|
|
42
|
+
print(risk.country) # Brasil
|
|
43
|
+
print(risk.congestion_score) # 0.78
|
|
44
|
+
print(risk.eta_delay_days) # 1.6
|
|
45
|
+
print(risk.waiting_vessels) # 12
|
|
46
|
+
print(risk.freight_volatility_index) # 0.42
|
|
47
|
+
print(risk.updated_at) # 2026-09-17 15:46:53
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Campos retornados (`PortRisk`)
|
|
51
|
+
|
|
52
|
+
| Campo | Tipo | Descrição |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| `port_id` | `str` | UN/LOCODE do porto (ex: `BRSSZ`) |
|
|
55
|
+
| `port_name` | `str` | Nome do porto |
|
|
56
|
+
| `country` | `str` | País do porto |
|
|
57
|
+
| `congestion_score` | `float` | Score de congestão (0.0 a 1.0) |
|
|
58
|
+
| `eta_delay_days` | `float` | Atraso estimado de ETA em dias |
|
|
59
|
+
| `waiting_vessels` | `int` | Navios aguardando/ancorados |
|
|
60
|
+
| `freight_volatility_index` | `float` | Índice de volatilidade de frete |
|
|
61
|
+
| `updated_at` | `str` | Timestamp da última atualização |
|
|
62
|
+
|
|
63
|
+
## Configuração avançada
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
client = OracleClient(
|
|
67
|
+
api_key="SUA_RAPIDAPI_KEY",
|
|
68
|
+
host="aether-x-port-congestion-oracle.p.rapidapi.com", # default
|
|
69
|
+
timeout=30.0, # segundos
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Portos suportados
|
|
74
|
+
|
|
75
|
+
Portos com dados de exemplo: `BRSSZ`, `BRRIO`, `CNSHA`, `CNNGB`, `SGSIN`, `NLRTM`, `USLAX`, `USNYC`, `DEHAM`, `MPTNG`, `AEDXB`, `KRPUS`, `GBLGP`, `ZACPT`, `MXZLO`.
|
|
76
|
+
|
|
77
|
+
Portos não cadastrados retornam uma estimativa global (`country="Global"`).
|
|
78
|
+
|
|
79
|
+
## Uso assíncrono (async)
|
|
80
|
+
|
|
81
|
+
Para consultar múltiplos portos em paralelo (ideal para bots e fundos quantitativos). Requer o extra `async`:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install "aetherx-oracle[async]"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import asyncio
|
|
89
|
+
from aetherx import OracleClient
|
|
90
|
+
|
|
91
|
+
async def main():
|
|
92
|
+
client = OracleClient(api_key="SUA_RAPIDAPI_KEY")
|
|
93
|
+
|
|
94
|
+
# Um porto
|
|
95
|
+
risk = await client.get_port_risk_async("BRSSZ")
|
|
96
|
+
print(risk.congestion_score)
|
|
97
|
+
|
|
98
|
+
# Vários portos em paralelo
|
|
99
|
+
risks = await client.get_ports_risk_async(["BRSSZ", "CNSHA", "NLRTM"])
|
|
100
|
+
for r in risks:
|
|
101
|
+
print(r.port_id, r.congestion_score)
|
|
102
|
+
|
|
103
|
+
asyncio.run(main())
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Termos de uso
|
|
107
|
+
|
|
108
|
+
Os sinais são fornecidos "AS IS", sem garantia e **não constituem aconselhamento de investimento**. Consulte os [Termos de Serviço](https://aether-x-oracle-production.up.railway.app/terms).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
aetherx/__init__.py,sha256=Ikx1KnIHbPfXJGo9FDUAWbL5x-z0W1lqHU4Tu3wTZfQ,128
|
|
2
|
+
aetherx/client.py,sha256=CuXph0_Jj_NRZnF33YcHiY0wN0E8EKen0TX_drFWfxs,4310
|
|
3
|
+
aetherx_oracle-0.3.0.dist-info/METADATA,sha256=zmL21LONdFv3FNAwAOd1qFDw0rc079p0D-lOi7IADEc,3487
|
|
4
|
+
aetherx_oracle-0.3.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
5
|
+
aetherx_oracle-0.3.0.dist-info/top_level.txt,sha256=jFkXoJMGdDpj1pdc3rxjTtlYDCBNCyzJklBUUrtdBbc,8
|
|
6
|
+
aetherx_oracle-0.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aetherx
|