galon 1.0.0__tar.gz
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.
- galon-1.0.0/PKG-INFO +138 -0
- galon-1.0.0/README.md +119 -0
- galon-1.0.0/pyproject.toml +38 -0
- galon-1.0.0/setup.cfg +4 -0
- galon-1.0.0/src/galon/__init__.py +91 -0
- galon-1.0.0/src/galon/_errors.py +110 -0
- galon-1.0.0/src/galon/_generated_models.py +1893 -0
- galon-1.0.0/src/galon/_generated_resources.py +440 -0
- galon-1.0.0/src/galon/_generated_routes.py +689 -0
- galon-1.0.0/src/galon/_generated_services.py +262 -0
- galon-1.0.0/src/galon/_http.py +146 -0
- galon-1.0.0/src/galon/_serialize.py +50 -0
- galon-1.0.0/src/galon/cli.py +345 -0
- galon-1.0.0/src/galon/cli_complete.py +1055 -0
- galon-1.0.0/src/galon/galon_catalogue.py +2276 -0
- galon-1.0.0/src/galon/galon_commandes.py +1019 -0
- galon-1.0.0/src/galon/galon_connexion.py +295 -0
- galon-1.0.0/src/galon/mcp_server.py +303 -0
- galon-1.0.0/src/galon/py.typed +0 -0
- galon-1.0.0/src/galon/resources.py +53 -0
- galon-1.0.0/src/galon/terminal.py +122 -0
- galon-1.0.0/src/galon/webhooks.py +81 -0
- galon-1.0.0/src/galon.egg-info/PKG-INFO +138 -0
- galon-1.0.0/src/galon.egg-info/SOURCES.txt +29 -0
- galon-1.0.0/src/galon.egg-info/dependency_links.txt +1 -0
- galon-1.0.0/src/galon.egg-info/entry_points.txt +3 -0
- galon-1.0.0/src/galon.egg-info/top_level.txt +1 -0
- galon-1.0.0/tests/test_cli.py +307 -0
- galon-1.0.0/tests/test_client.py +381 -0
- galon-1.0.0/tests/test_mcp.py +145 -0
- galon-1.0.0/tests/test_services.py +86 -0
galon-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: galon
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Galon Cloud SDK for Python: Mail, AI, Geo, Search, Storage, Backend, Compute, Deploy, Domains, Functions.
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://cloud.galon.ai
|
|
7
|
+
Project-URL: Documentation, https://cloud.galon.ai/cloud/docs
|
|
8
|
+
Project-URL: Source, https://github.com/galon-ai/galon-python
|
|
9
|
+
Project-URL: Issues, https://github.com/galon-ai/galon-python/issues
|
|
10
|
+
Keywords: galon,cloud,email,transactional,geocoding,maps,search,storage,ai,llm,deploy,domains,postgres,mcp,ai-agents,sdk
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Communications :: Email
|
|
15
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# galon — the Galon Cloud SDK for Python
|
|
21
|
+
|
|
22
|
+
Prepaid cloud services for apps and AI agents, with spending caps the server enforces: Mail, AI, Geo,
|
|
23
|
+
Search, Storage, Backend, Compute, Deploy, Domains and Functions behind one API key.
|
|
24
|
+
Standard library only, Python 3.9+. Includes the `galon` command line and the `galon-mcp` server.
|
|
25
|
+
|
|
26
|
+
Documentation: https://cloud.galon.ai/cloud/docs · API reference (OpenAPI): https://cloud.galon.ai/cloud/docs/openapi.json
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install galon
|
|
30
|
+
export GALON_API_KEY="gln_test_..." # a test key from https://cloud.galon.ai/cloud/keys
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from galon import Galon
|
|
35
|
+
|
|
36
|
+
galon = Galon() # reads GALON_API_KEY (and GALON_PROJECT_ID, GALON_BASE_URL when set)
|
|
37
|
+
|
|
38
|
+
# Mail
|
|
39
|
+
sent = galon.emails.send(
|
|
40
|
+
{"from": "hello@your-domain.com", "to": "ana@example.com", "subject": "Welcome",
|
|
41
|
+
"html": "<p>Welcome aboard</p>"},
|
|
42
|
+
idempotency_key="signup-42-welcome",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# Geo
|
|
46
|
+
place = galon.geo.geocode_address({"q": "10 Downing Street, London", "country": "GB"})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Only the services open to your project answer; the others return `404` or `403` with an error code.
|
|
50
|
+
Call `galon.tools.get()` to see what your key can use.
|
|
51
|
+
|
|
52
|
+
## Services
|
|
53
|
+
|
|
54
|
+
| Service | Client | Notes |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| Mail | `emails`, `batch`, `domains`, `templates`, `suppressions`, `webhooks`, `received_emails`, `receiving_domains` | Transactional email from your own domain |
|
|
57
|
+
| AI | `ai` | Chat completions and embeddings. Any OpenAI-compatible (Chat Completions) client also works: set its base URL to `https://api.galon.ai/v1/ai` and use your Galon key as the API key |
|
|
58
|
+
| Geo | `geo` | Geocoding, reverse geocoding, places, autocomplete, routes, distance matrix, isochrones, basemap style |
|
|
59
|
+
| Search | `search`, `search_indexes` | Page scraping, site maps and crawls; full-text indexes, documents and queries |
|
|
60
|
+
| Storage | `buckets`, `uploads`, `objects`, `storage` | Buckets and objects through the Galon API (upload, commit, versions, signed links). There is no S3 endpoint today |
|
|
61
|
+
| Backend | `backend` | Hosted Postgres databases and migrations |
|
|
62
|
+
| Compute | `compute` | Virtual machines: flavors, images, SSH keys, quotes, instances |
|
|
63
|
+
| Deploy | `deployments`, `previews`, `deploy`, `production` | Preview deploys (from a repository or an archive), logs, production |
|
|
64
|
+
| Domains | `domain_names`, `jobs` | Owned domains, quotes and orders; availability checks run as jobs |
|
|
65
|
+
| Functions | `functions` | Upload a source, deploy, follow the job |
|
|
66
|
+
| Account | `tools`, `costs`, `metering`, `limits`, `estimates`, `preparations` | What the key can do, spend, usage and caps |
|
|
67
|
+
|
|
68
|
+
Every namespace method is one served route: JSON in, JSON out. `sdks/spec/routes.json` and
|
|
69
|
+
`sdks/spec/services.json` list them all, generated from the published OpenAPI contract and the MCP
|
|
70
|
+
tool catalogue.
|
|
71
|
+
|
|
72
|
+
## Behaviour
|
|
73
|
+
|
|
74
|
+
- An `Idempotency-Key` on every mutation (pass `idempotency_key=...` to make retries safe), reused by retries.
|
|
75
|
+
- Retries on 429 (honouring `Retry-After`), 5xx and network errors, with a growing delay.
|
|
76
|
+
- Typed errors: `GalonValidationError`, `GalonAuthenticationError`, `GalonPermissionError`,
|
|
77
|
+
`GalonNotFoundError`, `GalonConflictError`, `GalonRateLimitError`, `GalonServerError`,
|
|
78
|
+
`GalonConnectionError`; each carries `status`, `code` and the API's `next_action` when present.
|
|
79
|
+
- The key never appears in `repr()`, logs or exceptions.
|
|
80
|
+
|
|
81
|
+
## Webhooks
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import os
|
|
85
|
+
from galon import verify_webhook
|
|
86
|
+
|
|
87
|
+
event = verify_webhook(raw_body, request.headers, secret=os.environ["GALON_WEBHOOK_SECRET"])
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Command line
|
|
91
|
+
|
|
92
|
+
`pip install galon` installs the `galon` command. Sign in once in the browser, no key to copy:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
galon login # opens the browser: sign in to Galon, choose the project, Allow
|
|
96
|
+
galon deploy ./dist # a static folder (index.html at its root) to a private preview
|
|
97
|
+
galon status djy_... # a deploy and its steps
|
|
98
|
+
galon deploy list # recent preview deploys
|
|
99
|
+
galon deploy logs djy_... --follow
|
|
100
|
+
galon promote djy_... --yes # a verified preview becomes production (live project)
|
|
101
|
+
galon rollback --yes
|
|
102
|
+
galon --json deploy list # raw JSON, for scripts
|
|
103
|
+
galon logout
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
On a server or in CI, use a key instead of the browser: `export GALON_API_KEY=gln_test_...` then
|
|
107
|
+
`galon login --with-key` (never echoed, stored with mode 0600). A key on the command line is refused.
|
|
108
|
+
Exit codes are stable: `galon --help` lists them (3 means not signed in).
|
|
109
|
+
|
|
110
|
+
The SDK commands use the key of `GALON_API_KEY` and print JSON:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
galon capabilities # tools allowed by its scopes
|
|
114
|
+
galon emails send --from hello@your-domain.com --to ana@example.com --subject Hi --text "Hello" \
|
|
115
|
+
--idempotency-key signup-42
|
|
116
|
+
galon deploy status
|
|
117
|
+
galon costs status
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Their exit codes: 0 success, 1 API error, 2 usage error or no key, 3 capability not published.
|
|
121
|
+
In Python, `galon.cli.main` is the SDK command line and `galon.terminal.main` the `galon` command.
|
|
122
|
+
|
|
123
|
+
## MCP
|
|
124
|
+
|
|
125
|
+
For AI assistants, prefer the remote Galon MCP server: `https://api.galon.ai/v1/mcp` (sign in with
|
|
126
|
+
Galon, no key to copy). Setup for each client: https://cloud.galon.ai/mcp.md.
|
|
127
|
+
|
|
128
|
+
This package also ships `galon-mcp`, a local stdio server for email tools (`uvx --from galon galon-mcp`),
|
|
129
|
+
which reads `GALON_API_KEY` from its environment. `send_email` asks the human to confirm before
|
|
130
|
+
anything is sent; `GALON_MCP_READ_ONLY=1` removes it.
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
cd tests && python3 -m unittest discover # fake transport, no network
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Licence: MIT. Security reports: see SECURITY.md in the repository.
|
galon-1.0.0/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# galon — the Galon Cloud SDK for Python
|
|
2
|
+
|
|
3
|
+
Prepaid cloud services for apps and AI agents, with spending caps the server enforces: Mail, AI, Geo,
|
|
4
|
+
Search, Storage, Backend, Compute, Deploy, Domains and Functions behind one API key.
|
|
5
|
+
Standard library only, Python 3.9+. Includes the `galon` command line and the `galon-mcp` server.
|
|
6
|
+
|
|
7
|
+
Documentation: https://cloud.galon.ai/cloud/docs · API reference (OpenAPI): https://cloud.galon.ai/cloud/docs/openapi.json
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install galon
|
|
11
|
+
export GALON_API_KEY="gln_test_..." # a test key from https://cloud.galon.ai/cloud/keys
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from galon import Galon
|
|
16
|
+
|
|
17
|
+
galon = Galon() # reads GALON_API_KEY (and GALON_PROJECT_ID, GALON_BASE_URL when set)
|
|
18
|
+
|
|
19
|
+
# Mail
|
|
20
|
+
sent = galon.emails.send(
|
|
21
|
+
{"from": "hello@your-domain.com", "to": "ana@example.com", "subject": "Welcome",
|
|
22
|
+
"html": "<p>Welcome aboard</p>"},
|
|
23
|
+
idempotency_key="signup-42-welcome",
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# Geo
|
|
27
|
+
place = galon.geo.geocode_address({"q": "10 Downing Street, London", "country": "GB"})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Only the services open to your project answer; the others return `404` or `403` with an error code.
|
|
31
|
+
Call `galon.tools.get()` to see what your key can use.
|
|
32
|
+
|
|
33
|
+
## Services
|
|
34
|
+
|
|
35
|
+
| Service | Client | Notes |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| Mail | `emails`, `batch`, `domains`, `templates`, `suppressions`, `webhooks`, `received_emails`, `receiving_domains` | Transactional email from your own domain |
|
|
38
|
+
| AI | `ai` | Chat completions and embeddings. Any OpenAI-compatible (Chat Completions) client also works: set its base URL to `https://api.galon.ai/v1/ai` and use your Galon key as the API key |
|
|
39
|
+
| Geo | `geo` | Geocoding, reverse geocoding, places, autocomplete, routes, distance matrix, isochrones, basemap style |
|
|
40
|
+
| Search | `search`, `search_indexes` | Page scraping, site maps and crawls; full-text indexes, documents and queries |
|
|
41
|
+
| Storage | `buckets`, `uploads`, `objects`, `storage` | Buckets and objects through the Galon API (upload, commit, versions, signed links). There is no S3 endpoint today |
|
|
42
|
+
| Backend | `backend` | Hosted Postgres databases and migrations |
|
|
43
|
+
| Compute | `compute` | Virtual machines: flavors, images, SSH keys, quotes, instances |
|
|
44
|
+
| Deploy | `deployments`, `previews`, `deploy`, `production` | Preview deploys (from a repository or an archive), logs, production |
|
|
45
|
+
| Domains | `domain_names`, `jobs` | Owned domains, quotes and orders; availability checks run as jobs |
|
|
46
|
+
| Functions | `functions` | Upload a source, deploy, follow the job |
|
|
47
|
+
| Account | `tools`, `costs`, `metering`, `limits`, `estimates`, `preparations` | What the key can do, spend, usage and caps |
|
|
48
|
+
|
|
49
|
+
Every namespace method is one served route: JSON in, JSON out. `sdks/spec/routes.json` and
|
|
50
|
+
`sdks/spec/services.json` list them all, generated from the published OpenAPI contract and the MCP
|
|
51
|
+
tool catalogue.
|
|
52
|
+
|
|
53
|
+
## Behaviour
|
|
54
|
+
|
|
55
|
+
- An `Idempotency-Key` on every mutation (pass `idempotency_key=...` to make retries safe), reused by retries.
|
|
56
|
+
- Retries on 429 (honouring `Retry-After`), 5xx and network errors, with a growing delay.
|
|
57
|
+
- Typed errors: `GalonValidationError`, `GalonAuthenticationError`, `GalonPermissionError`,
|
|
58
|
+
`GalonNotFoundError`, `GalonConflictError`, `GalonRateLimitError`, `GalonServerError`,
|
|
59
|
+
`GalonConnectionError`; each carries `status`, `code` and the API's `next_action` when present.
|
|
60
|
+
- The key never appears in `repr()`, logs or exceptions.
|
|
61
|
+
|
|
62
|
+
## Webhooks
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import os
|
|
66
|
+
from galon import verify_webhook
|
|
67
|
+
|
|
68
|
+
event = verify_webhook(raw_body, request.headers, secret=os.environ["GALON_WEBHOOK_SECRET"])
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Command line
|
|
72
|
+
|
|
73
|
+
`pip install galon` installs the `galon` command. Sign in once in the browser, no key to copy:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
galon login # opens the browser: sign in to Galon, choose the project, Allow
|
|
77
|
+
galon deploy ./dist # a static folder (index.html at its root) to a private preview
|
|
78
|
+
galon status djy_... # a deploy and its steps
|
|
79
|
+
galon deploy list # recent preview deploys
|
|
80
|
+
galon deploy logs djy_... --follow
|
|
81
|
+
galon promote djy_... --yes # a verified preview becomes production (live project)
|
|
82
|
+
galon rollback --yes
|
|
83
|
+
galon --json deploy list # raw JSON, for scripts
|
|
84
|
+
galon logout
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
On a server or in CI, use a key instead of the browser: `export GALON_API_KEY=gln_test_...` then
|
|
88
|
+
`galon login --with-key` (never echoed, stored with mode 0600). A key on the command line is refused.
|
|
89
|
+
Exit codes are stable: `galon --help` lists them (3 means not signed in).
|
|
90
|
+
|
|
91
|
+
The SDK commands use the key of `GALON_API_KEY` and print JSON:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
galon capabilities # tools allowed by its scopes
|
|
95
|
+
galon emails send --from hello@your-domain.com --to ana@example.com --subject Hi --text "Hello" \
|
|
96
|
+
--idempotency-key signup-42
|
|
97
|
+
galon deploy status
|
|
98
|
+
galon costs status
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Their exit codes: 0 success, 1 API error, 2 usage error or no key, 3 capability not published.
|
|
102
|
+
In Python, `galon.cli.main` is the SDK command line and `galon.terminal.main` the `galon` command.
|
|
103
|
+
|
|
104
|
+
## MCP
|
|
105
|
+
|
|
106
|
+
For AI assistants, prefer the remote Galon MCP server: `https://api.galon.ai/v1/mcp` (sign in with
|
|
107
|
+
Galon, no key to copy). Setup for each client: https://cloud.galon.ai/mcp.md.
|
|
108
|
+
|
|
109
|
+
This package also ships `galon-mcp`, a local stdio server for email tools (`uvx --from galon galon-mcp`),
|
|
110
|
+
which reads `GALON_API_KEY` from its environment. `send_email` asks the human to confirm before
|
|
111
|
+
anything is sent; `GALON_MCP_READ_ONLY=1` removes it.
|
|
112
|
+
|
|
113
|
+
## Development
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
cd tests && python3 -m unittest discover # fake transport, no network
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Licence: MIT. Security reports: see SECURITY.md in the repository.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "galon"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Official Galon Cloud SDK for Python: Mail, AI, Geo, Search, Storage, Backend, Compute, Deploy, Domains, Functions."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
dependencies = []
|
|
13
|
+
keywords = ["galon", "cloud", "email", "transactional", "geocoding", "maps", "search", "storage", "ai", "llm", "deploy",
|
|
14
|
+
"domains", "postgres", "mcp", "ai-agents", "sdk"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Topic :: Communications :: Email",
|
|
20
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
21
|
+
"Topic :: Software Development :: Libraries",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://cloud.galon.ai"
|
|
26
|
+
Documentation = "https://cloud.galon.ai/cloud/docs"
|
|
27
|
+
Source = "https://github.com/galon-ai/galon-python"
|
|
28
|
+
Issues = "https://github.com/galon-ai/galon-python/issues"
|
|
29
|
+
|
|
30
|
+
[project.scripts]
|
|
31
|
+
galon = "galon.terminal:main"
|
|
32
|
+
galon-mcp = "galon.mcp_server:main"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["src"]
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.package-data]
|
|
38
|
+
galon = ["py.typed"]
|
galon-1.0.0/setup.cfg
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Galon Cloud SDK for Python (standard library only): Mail, AI, Geo, Search, Storage, Backend, Compute, Deploy,
|
|
2
|
+
Domains and Functions.
|
|
3
|
+
|
|
4
|
+
from galon import Galon
|
|
5
|
+
galon = Galon() # reads GALON_API_KEY
|
|
6
|
+
galon.emails.send({"from": "you@your-domain.com", "to": "ana@example.com",
|
|
7
|
+
"subject": "Hi", "html": "<p>Hi</p>"})
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import Any, Optional
|
|
12
|
+
|
|
13
|
+
from ._errors import (GalonAuthenticationError, GalonConflictError, GalonConnectionError, GalonError,
|
|
14
|
+
GalonNotFoundError, GalonPermissionError, GalonRateLimitError, GalonServerError,
|
|
15
|
+
GalonValidationError, GalonWebhookVerificationError)
|
|
16
|
+
from ._http import DEFAULT_BASE_URL, VERSION, HttpClient, backoff, parse_retry_after
|
|
17
|
+
from ._generated_models import * # noqa: F403 — surface publique générée depuis l'OpenAPI
|
|
18
|
+
from ._generated_models import __all__ as _MODEL_NAMES
|
|
19
|
+
from ._serialize import serialize_email
|
|
20
|
+
from .resources import (BETA, RESOURCES, ApiKeys, Artifacts, Batch, Builds, Contacts, Costs,
|
|
21
|
+
DomainActions, Domains, Emails, Estimates, Jobs, Limits, Metering,
|
|
22
|
+
Preparations, Segments, Templates, Tools, Topics, Webhooks,
|
|
23
|
+
Suppressions, ReceivedEmails, ReceivingDomains, Ai, Buckets, Uploads, Objects,
|
|
24
|
+
Storage, Deployments, Deploy, Production, Search)
|
|
25
|
+
from ._generated_services import SERVICE_RESOURCES # lot geo-c : namespaces par service, générés
|
|
26
|
+
from ._generated_services import Backend, Compute, DomainNames, Functions, Geo, Previews, SearchIndexes, StorageExtra
|
|
27
|
+
from .webhooks import (EVENT_ID_HEADER, SIGNATURE_HEADER, compute_signature, parse_signature_header,
|
|
28
|
+
verify_webhook)
|
|
29
|
+
|
|
30
|
+
__version__ = VERSION
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Galon:
|
|
34
|
+
"""Client. Keyword options: base_url, project_id, max_retries, timeout, transport, sleep, idempotency_key."""
|
|
35
|
+
|
|
36
|
+
emails: Emails
|
|
37
|
+
batch: Batch
|
|
38
|
+
jobs: Jobs
|
|
39
|
+
domain_actions: DomainActions
|
|
40
|
+
tools: Tools
|
|
41
|
+
costs: Costs
|
|
42
|
+
metering: Metering
|
|
43
|
+
limits: Limits
|
|
44
|
+
estimates: Estimates
|
|
45
|
+
preparations: Preparations
|
|
46
|
+
builds: Builds
|
|
47
|
+
artifacts: Artifacts
|
|
48
|
+
domains: Domains
|
|
49
|
+
api_keys: ApiKeys
|
|
50
|
+
webhooks: Webhooks
|
|
51
|
+
contacts: Contacts
|
|
52
|
+
segments: Segments
|
|
53
|
+
topics: Topics
|
|
54
|
+
templates: Templates
|
|
55
|
+
suppressions: Suppressions
|
|
56
|
+
received_emails: ReceivedEmails
|
|
57
|
+
receiving_domains: ReceivingDomains
|
|
58
|
+
ai: Ai
|
|
59
|
+
buckets: Buckets
|
|
60
|
+
uploads: Uploads
|
|
61
|
+
objects: Objects
|
|
62
|
+
storage: Storage
|
|
63
|
+
deployments: Deployments
|
|
64
|
+
deploy: Deploy
|
|
65
|
+
production: Production
|
|
66
|
+
search: Search
|
|
67
|
+
search_indexes: SearchIndexes
|
|
68
|
+
storage_extra: StorageExtra
|
|
69
|
+
previews: Previews
|
|
70
|
+
geo: Geo
|
|
71
|
+
compute: Compute
|
|
72
|
+
backend: Backend
|
|
73
|
+
functions: Functions
|
|
74
|
+
domain_names: DomainNames
|
|
75
|
+
|
|
76
|
+
def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
|
|
77
|
+
self.http = HttpClient(api_key, **options)
|
|
78
|
+
for name, cls in {**RESOURCES, **SERVICE_RESOURCES}.items():
|
|
79
|
+
setattr(self, name, cls(self.http))
|
|
80
|
+
|
|
81
|
+
def __repr__(self) -> str:
|
|
82
|
+
return "Galon(%r)" % self.http
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
__all__ = [
|
|
86
|
+
"Galon", "HttpClient", "VERSION", "DEFAULT_BASE_URL", "BETA", "serialize_email", "verify_webhook",
|
|
87
|
+
"compute_signature", "parse_signature_header", "SIGNATURE_HEADER", "EVENT_ID_HEADER", "backoff",
|
|
88
|
+
"parse_retry_after", "GalonError", "GalonValidationError", "GalonAuthenticationError",
|
|
89
|
+
"GalonPermissionError", "GalonNotFoundError", "GalonConflictError", "GalonRateLimitError",
|
|
90
|
+
"GalonServerError", "GalonConnectionError", "GalonWebhookVerificationError",
|
|
91
|
+
] + _MODEL_NAMES
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Typed errors. Every API failure is a ``GalonError``; the subclass tells what to do next."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Any, Dict, Optional
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class GalonError(Exception):
|
|
8
|
+
def __init__(self, message: str, *, status: Optional[int] = None, code: str = "galon_error",
|
|
9
|
+
body: Any = None, headers: Optional[Dict[str, str]] = None,
|
|
10
|
+
retry_after: Optional[float] = None,
|
|
11
|
+
next_action: Optional[Dict[str, Any]] = None) -> None:
|
|
12
|
+
super().__init__(message)
|
|
13
|
+
self.message = message
|
|
14
|
+
self.status = status
|
|
15
|
+
self.code = code
|
|
16
|
+
self.body = body
|
|
17
|
+
self.headers = headers or {}
|
|
18
|
+
self.retry_after = retry_after
|
|
19
|
+
#: What to do next, from the API: ``{"code", "hint", "docs_url", "console_url"?}`` (None if absent).
|
|
20
|
+
self.next_action = next_action
|
|
21
|
+
|
|
22
|
+
def __repr__(self) -> str:
|
|
23
|
+
return "%s(status=%r, code=%r, message=%r)" % (type(self).__name__, self.status, self.code, self.message)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class GalonValidationError(GalonError):
|
|
27
|
+
"""400, 413, 422: repair the request before sending it again."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class GalonAuthenticationError(GalonError):
|
|
31
|
+
"""401: missing, invalid, revoked or expired key."""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class GalonPermissionError(GalonError):
|
|
35
|
+
"""403: valid key without the scope (for example ``mail:send``)."""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class GalonNotFoundError(GalonError):
|
|
39
|
+
"""404: not visible from this key's tenant, project and environment."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class GalonConflictError(GalonError):
|
|
43
|
+
"""409: idempotency or state conflict. Do not change the intent under the same key."""
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def is_idempotency_conflict(self) -> bool:
|
|
47
|
+
return self.code == "idempotency_conflict"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class GalonRateLimitError(GalonError):
|
|
51
|
+
"""429: quota or rate limit. ``retry_after`` (seconds) carries the server delay when present."""
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class GalonServerError(GalonError):
|
|
55
|
+
"""5xx: temporary failure on Galon's side, after the automatic retries."""
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class GalonConnectionError(GalonError):
|
|
59
|
+
"""The request never got an HTTP answer (network, DNS, timeout)."""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class GalonWebhookVerificationError(GalonError):
|
|
63
|
+
"""A webhook payload whose signature, timestamp or format does not verify."""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _detail(body: Any):
|
|
67
|
+
if isinstance(body, dict):
|
|
68
|
+
inner = body.get("detail", body.get("error", body))
|
|
69
|
+
if isinstance(inner, dict):
|
|
70
|
+
code = inner.get("code") if isinstance(inner.get("code"), str) else None
|
|
71
|
+
message = inner.get("message") if isinstance(inner.get("message"), str) else None
|
|
72
|
+
return code, message
|
|
73
|
+
if isinstance(inner, str):
|
|
74
|
+
return None, inner
|
|
75
|
+
return None, None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _next_action(body: Any) -> Optional[Dict[str, Any]]:
|
|
79
|
+
"""``detail.next_action``, else a top-level ``next_action`` (when ``detail`` is not an object)."""
|
|
80
|
+
if not isinstance(body, dict):
|
|
81
|
+
return None
|
|
82
|
+
detail = body.get("detail")
|
|
83
|
+
for candidate in ((detail.get("next_action") if isinstance(detail, dict) else None), body.get("next_action")):
|
|
84
|
+
if isinstance(candidate, dict) and isinstance(candidate.get("code"), str) \
|
|
85
|
+
and isinstance(candidate.get("hint"), str):
|
|
86
|
+
return dict(candidate)
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def error_from_response(status: int, body: Any, headers: Dict[str, str],
|
|
91
|
+
retry_after: Optional[float] = None) -> GalonError:
|
|
92
|
+
code, message = _detail(body)
|
|
93
|
+
kw = dict(status=status, code=code or "http_%d" % status, body=body, headers=headers,
|
|
94
|
+
retry_after=retry_after, next_action=_next_action(body))
|
|
95
|
+
message = message or "Galon API answered HTTP %d" % status
|
|
96
|
+
if status == 401:
|
|
97
|
+
return GalonAuthenticationError(message, **kw)
|
|
98
|
+
if status == 403:
|
|
99
|
+
return GalonPermissionError(message, **kw)
|
|
100
|
+
if status == 404:
|
|
101
|
+
return GalonNotFoundError(message, **kw)
|
|
102
|
+
if status == 409:
|
|
103
|
+
return GalonConflictError(message, **kw)
|
|
104
|
+
if status == 429:
|
|
105
|
+
return GalonRateLimitError(message, **kw)
|
|
106
|
+
if status >= 500:
|
|
107
|
+
return GalonServerError(message, **kw)
|
|
108
|
+
if status in (400, 413, 422):
|
|
109
|
+
return GalonValidationError(message, **kw)
|
|
110
|
+
return GalonError(message, **kw)
|