polaris-python 0.0.1.dev3__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.
- polaris_python-0.0.1.dev3/LICENSE +18 -0
- polaris_python-0.0.1.dev3/PKG-INFO +213 -0
- polaris_python-0.0.1.dev3/README.md +182 -0
- polaris_python-0.0.1.dev3/pyproject.toml +56 -0
- polaris_python-0.0.1.dev3/setup.cfg +4 -0
- polaris_python-0.0.1.dev3/src/polaris/__init__.py +74 -0
- polaris_python-0.0.1.dev3/src/polaris/_version.py +16 -0
- polaris_python-0.0.1.dev3/src/polaris/api/__init__.py +55 -0
- polaris_python-0.0.1.dev3/src/polaris/api/_log_file.py +232 -0
- polaris_python-0.0.1.dev3/src/polaris/api/config.py +145 -0
- polaris_python-0.0.1.dev3/src/polaris/api/consumer.py +240 -0
- polaris_python-0.0.1.dev3/src/polaris/api/log.py +414 -0
- polaris_python-0.0.1.dev3/src/polaris/api/lossless.py +73 -0
- polaris_python-0.0.1.dev3/src/polaris/api/provider.py +152 -0
- polaris_python-0.0.1.dev3/src/polaris/api/skill.py +162 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/__init__.py +15 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/common/__init__.py +15 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/common/plugin.py +33 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/config/__init__.py +15 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/config/api.py +1205 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/config/default.py +92 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/config/event.py +76 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/config/loader.py +392 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/config/stat_reporter.py +100 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/flow/__init__.py +15 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/flow/admin_server.py +104 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/flow/async_flow.py +55 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/flow/base_flow.py +111 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/flow/impl.py +1277 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/flow/lossless.py +605 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/flow/notify.py +46 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/flow/register.py +210 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/flow/skill.py +110 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/flow/sync_flow.py +20 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/__init__.py +15 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/context.py +53 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/contract.py +89 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/core.py +51 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/engine.py +83 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/error.py +94 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/event.py +159 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/lossless.py +102 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/rule.py +152 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/server.py +288 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/service.py +820 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/skill.py +179 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/stat.py +168 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/model/util.py +58 -0
- polaris_python-0.0.1.dev3/src/polaris/pkg/version/__init__.py +18 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/__init__.py +32 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/circuit_breaker/__init__.py +19 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/circuit_breaker/base.py +54 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/circuit_breaker/composite.py +265 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/circuit_breaker/config.py +36 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/event/__init__.py +21 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/event/pushgateway.py +202 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/load_balancer/__init__.py +24 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/load_balancer/base.py +30 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/load_balancer/random.py +39 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/load_balancer/weighted_random.py +50 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/local_registry/__init__.py +18 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/local_registry/base.py +47 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/local_registry/file_cache.py +335 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/local_registry/local_cache.py +433 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/server_connector/__init__.py +20 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/server_connector/base.py +104 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/server_connector/convert.py +149 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/server_connector/grpc_connector/__init__.py +21 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/server_connector/grpc_connector/connection.py +401 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/server_connector/grpc_connector/grpc_client.py +384 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/server_connector/grpc_connector/tls.py +45 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/service_router/__init__.py +28 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/service_router/base.py +105 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/service_router/isolated.py +35 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/service_router/metadata.py +84 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/service_router/recover.py +62 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/service_router/util.py +54 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/skill/__init__.py +16 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/skill/connector.py +127 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/skill/persistence.py +94 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/stat_reporter/__init__.py +16 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/stat_reporter/base.py +34 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin/stat_reporter/prometheus.py +375 -0
- polaris_python-0.0.1.dev3/src/polaris/plugin_manager.py +146 -0
- polaris_python-0.0.1.dev3/src/polaris_python.egg-info/PKG-INFO +213 -0
- polaris_python-0.0.1.dev3/src/polaris_python.egg-info/SOURCES.txt +110 -0
- polaris_python-0.0.1.dev3/src/polaris_python.egg-info/dependency_links.txt +1 -0
- polaris_python-0.0.1.dev3/src/polaris_python.egg-info/requires.txt +7 -0
- polaris_python-0.0.1.dev3/src/polaris_python.egg-info/top_level.txt +1 -0
- polaris_python-0.0.1.dev3/tests/test_ai.py +868 -0
- polaris_python-0.0.1.dev3/tests/test_api.py +119 -0
- polaris_python-0.0.1.dev3/tests/test_circuitbreaker.py +857 -0
- polaris_python-0.0.1.dev3/tests/test_circuitbreaker_examples.py +231 -0
- polaris_python-0.0.1.dev3/tests/test_config.py +783 -0
- polaris_python-0.0.1.dev3/tests/test_context.py +959 -0
- polaris_python-0.0.1.dev3/tests/test_event_pushgateway.py +303 -0
- polaris_python-0.0.1.dev3/tests/test_events.py +198 -0
- polaris_python-0.0.1.dev3/tests/test_example_scripts.py +542 -0
- polaris_python-0.0.1.dev3/tests/test_impl.py +196 -0
- polaris_python-0.0.1.dev3/tests/test_loadbalance.py +65 -0
- polaris_python-0.0.1.dev3/tests/test_localregistry.py +959 -0
- polaris_python-0.0.1.dev3/tests/test_log.py +835 -0
- polaris_python-0.0.1.dev3/tests/test_lossless.py +1016 -0
- polaris_python-0.0.1.dev3/tests/test_mcp_examples.py +251 -0
- polaris_python-0.0.1.dev3/tests/test_p0_discovery.py +246 -0
- polaris_python-0.0.1.dev3/tests/test_provider.py +600 -0
- polaris_python-0.0.1.dev3/tests/test_serverconnector.py +462 -0
- polaris_python-0.0.1.dev3/tests/test_servicerouter.py +220 -0
- polaris_python-0.0.1.dev3/tests/test_snapshot_workflow.py +157 -0
- polaris_python-0.0.1.dev3/tests/test_stat_reporter.py +489 -0
- polaris_python-0.0.1.dev3/tests/test_tls.py +133 -0
- polaris_python-0.0.1.dev3/tests/test_util.py +189 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Tencent is pleased to support the open source community by making polaris-python available.
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2021 Tencent. All rights reserved.
|
|
4
|
+
|
|
5
|
+
A polaris-python is licensed under the BSD 3-Clause License. A copy of the BSD 3-Clause License is included in this file.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Terms of BSD 3-Clause License
|
|
9
|
+
---------------------------------------------------
|
|
10
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
11
|
+
|
|
12
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
13
|
+
|
|
14
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: polaris-python
|
|
3
|
+
Version: 0.0.1.dev3
|
|
4
|
+
Summary: Python SDK for Polaris service governance.
|
|
5
|
+
Author-email: evelynwei <evelynwei@tencent.com>
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Project-URL: Homepage, https://github.com/polaris-contrib/polaris-python
|
|
8
|
+
Project-URL: Repository, https://github.com/polaris-contrib/polaris-python
|
|
9
|
+
Project-URL: Issues, https://github.com/polaris-contrib/polaris-python/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/polaris-contrib/polaris-python#readme
|
|
11
|
+
Keywords: polaris,service-governance,service-discovery,service-mesh,grpc
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: grpcio>=1.84.0
|
|
24
|
+
Requires-Dist: protobuf<8,>=7.35.1
|
|
25
|
+
Requires-Dist: polarismesh-specification==1.9.0.dev4
|
|
26
|
+
Requires-Dist: PyYAML<7,>=6.0.2
|
|
27
|
+
Requires-Dist: psutil<8,>=7.0
|
|
28
|
+
Requires-Dist: prometheus-client<1,>=0.21
|
|
29
|
+
Requires-Dist: aiohttp<4,>=3.11
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# Polaris Python SDK
|
|
33
|
+
|
|
34
|
+
[中文](README-zh.md)
|
|
35
|
+
|
|
36
|
+
Python client for Polaris service discovery, registration, service governance,
|
|
37
|
+
AI Registry resources, observability, and TLS.
|
|
38
|
+
|
|
39
|
+
The distribution is `polaris-python`; import it as `polaris`.
|
|
40
|
+
|
|
41
|
+
The categorized documentation index is [docs/README.md](docs/README.md).
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
Requires Python 3.12+.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
uv sync --group dev --locked
|
|
49
|
+
uv run pytest
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The project uses a `src` layout. `uv sync` installs `src/polaris/` in editable mode,
|
|
53
|
+
so source changes take effect immediately.
|
|
54
|
+
|
|
55
|
+
See [Version and release](docs/project/version-release.md) for release and development package publishing.
|
|
56
|
+
|
|
57
|
+
## Configure
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
global:
|
|
61
|
+
serverConnector:
|
|
62
|
+
addresses:
|
|
63
|
+
- ${POLARIS_SERVER_ADDRESS:127.0.0.1:8091}
|
|
64
|
+
token: ${POLARIS_TOKEN:}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Use `Configuration.from_file()` for YAML, `Configuration.from_env()` for environment
|
|
68
|
+
variables, or `Configuration.from_dict()` for code-owned mappings. Python durations
|
|
69
|
+
are integer milliseconds; YAML also accepts values such as `500ms`, `1s`, and `1m30s`.
|
|
70
|
+
|
|
71
|
+
See:
|
|
72
|
+
|
|
73
|
+
- [Configuration parameters](docs/config/configuration-reference.md)
|
|
74
|
+
- [Minimal YAML example](docs/config/polaris.yaml)
|
|
75
|
+
- [Environment variables and precedence](docs/config/environment-variables.md)
|
|
76
|
+
- [Minimal file example](examples/sdkconfig/file/polaris.yaml)
|
|
77
|
+
|
|
78
|
+
## Context
|
|
79
|
+
|
|
80
|
+
Each `SDKContext` owns its configuration snapshot, client ID, plugins, connections,
|
|
81
|
+
caches, tasks, and logs. Reuse one context for APIs that should share that client.
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from polaris import Configuration, init_context_by_config
|
|
85
|
+
|
|
86
|
+
config = Configuration()
|
|
87
|
+
config.set_default()
|
|
88
|
+
config.get_global().get_server_connector().addresses = ["127.0.0.1:8091"]
|
|
89
|
+
|
|
90
|
+
context = init_context_by_config(config)
|
|
91
|
+
try:
|
|
92
|
+
...
|
|
93
|
+
finally:
|
|
94
|
+
context.destroy()
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
API calls after `destroy()` raise `SDKError`.
|
|
98
|
+
|
|
99
|
+
## Provider
|
|
100
|
+
|
|
101
|
+
`ProviderAPI` supports synchronous methods and `async_` counterparts.
|
|
102
|
+
`register_instance()` enables SDK-managed heartbeats by default.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from polaris.pkg.model.server import InstanceRegisterRequest
|
|
106
|
+
|
|
107
|
+
response = provider.register_instance(InstanceRegisterRequest(
|
|
108
|
+
service="demo",
|
|
109
|
+
service_token="service-token",
|
|
110
|
+
namespace="default",
|
|
111
|
+
host="127.0.0.1",
|
|
112
|
+
port=8080,
|
|
113
|
+
ttl=5,
|
|
114
|
+
))
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The service token authorizes register, heartbeat, and deregister. It is different
|
|
118
|
+
from `POLARIS_TOKEN`, which authenticates the SDK connection.
|
|
119
|
+
|
|
120
|
+
Automatic re-registration runs after two consecutive `400202` responses and
|
|
121
|
+
`provider.minRegisterInterval`.
|
|
122
|
+
Deregistration stops heartbeat tasks before the RPC. Context destruction does not
|
|
123
|
+
implicitly deregister instances.
|
|
124
|
+
|
|
125
|
+
## Consumer
|
|
126
|
+
|
|
127
|
+
Reuse one `ConsumerAPI` per context. Synchronous calls are `get_one_instance()`,
|
|
128
|
+
`get_instances()`, `get_all_instances()`, `get_healthy_instances()`, and
|
|
129
|
+
`get_services()`; query methods have `async_` counterparts. `watch_service()` pins a
|
|
130
|
+
loaded resource and forwards cache lifecycle events; `unwatch_service()` releases it.
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from polaris.pkg.model.service import GetOneInstanceRequest
|
|
134
|
+
|
|
135
|
+
instance = consumer.get_one_instance(GetOneInstanceRequest(
|
|
136
|
+
namespace="default",
|
|
137
|
+
service="demo",
|
|
138
|
+
))
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
After invoking the downstream service, report the result with
|
|
142
|
+
`update_service_call_result()` or `async_update_service_call_result()`.
|
|
143
|
+
|
|
144
|
+
Local cache behavior, idle eviction, disk retries, and restart recovery are covered by
|
|
145
|
+
the examples and [configuration reference](docs/config/configuration-reference.md).
|
|
146
|
+
|
|
147
|
+
## AI Registry
|
|
148
|
+
|
|
149
|
+
- MCP, A2A, and LangGraph use ordinary `Instance` registration and discovery.
|
|
150
|
+
- Service contracts use `report_service_contract()` and `get_service_contract()`.
|
|
151
|
+
- `SkillAPI` provides read-only get/list/download operations over an independent connector.
|
|
152
|
+
- Skill downloads can fall back to versioned local backups after network errors.
|
|
153
|
+
|
|
154
|
+
See [AI Registry APIs](docs/guides/ai-registry.md) and:
|
|
155
|
+
|
|
156
|
+
- [MCP example](examples/mcp/README.md)
|
|
157
|
+
- [A2A example](examples/a2a/README.md)
|
|
158
|
+
- [Skill example](examples/skill/README.md)
|
|
159
|
+
|
|
160
|
+
## Plugins
|
|
161
|
+
|
|
162
|
+
| Kind | Names |
|
|
163
|
+
| --- | --- |
|
|
164
|
+
| Server connector | `grpc` |
|
|
165
|
+
| Local cache | `inmemory`, `file` |
|
|
166
|
+
| Service router | `isolatedRouter`, `metadataRouter`, `recoverRouter` |
|
|
167
|
+
| Load balancer | `weightedRandom`, `random` |
|
|
168
|
+
| Circuit breaker | `composite` |
|
|
169
|
+
| Stat reporter | `prometheus` (`pushgateway` chain alias for push mode) |
|
|
170
|
+
| Event reporter | `pushgateway` |
|
|
171
|
+
|
|
172
|
+
Legacy names `wr` and `err_count` normalize to `weightedRandom` and `composite`.
|
|
173
|
+
Remote lossless rules are supported. Remote circuit-breaking, routing, rate-limiting and
|
|
174
|
+
configuration rules remain disabled, and active health detection is not enabled.
|
|
175
|
+
|
|
176
|
+
## Observability And Security
|
|
177
|
+
|
|
178
|
+
Public cloud currently uses Pushgateway as the default supported export path.
|
|
179
|
+
Prometheus pull remains available for self-hosted or custom scraping setups.
|
|
180
|
+
See [Observability](docs/guides/observability.md).
|
|
181
|
+
|
|
182
|
+
Each context has an isolated event center for implemented instance-cache and local
|
|
183
|
+
circuit-breaker events, with an optional Pushgateway reporter. See
|
|
184
|
+
[Events](docs/guides/events.md).
|
|
185
|
+
|
|
186
|
+
The registry and Skill connectors support independent TLS and mTLS certificates.
|
|
187
|
+
Invalid certificate configuration fails startup instead of falling back to plaintext.
|
|
188
|
+
See [TLS](docs/guides/tls.md).
|
|
189
|
+
|
|
190
|
+
## Examples
|
|
191
|
+
|
|
192
|
+
Run all offline verifications:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
./examples/verify_all.sh
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Run or inspect a single demo:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
cd examples/quickstart
|
|
202
|
+
./run.sh --help
|
|
203
|
+
./verify.sh
|
|
204
|
+
./logs.sh --latest --tail 30
|
|
205
|
+
./cleanup.sh --force
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Start with [examples/README.md](examples/README.md). Real registry examples require
|
|
209
|
+
`POLARIS_E2E=1`.
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
[BSD 3-Clause](LICENSE)
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# Polaris Python SDK
|
|
2
|
+
|
|
3
|
+
[中文](README-zh.md)
|
|
4
|
+
|
|
5
|
+
Python client for Polaris service discovery, registration, service governance,
|
|
6
|
+
AI Registry resources, observability, and TLS.
|
|
7
|
+
|
|
8
|
+
The distribution is `polaris-python`; import it as `polaris`.
|
|
9
|
+
|
|
10
|
+
The categorized documentation index is [docs/README.md](docs/README.md).
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
Requires Python 3.12+.
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
uv sync --group dev --locked
|
|
18
|
+
uv run pytest
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The project uses a `src` layout. `uv sync` installs `src/polaris/` in editable mode,
|
|
22
|
+
so source changes take effect immediately.
|
|
23
|
+
|
|
24
|
+
See [Version and release](docs/project/version-release.md) for release and development package publishing.
|
|
25
|
+
|
|
26
|
+
## Configure
|
|
27
|
+
|
|
28
|
+
```yaml
|
|
29
|
+
global:
|
|
30
|
+
serverConnector:
|
|
31
|
+
addresses:
|
|
32
|
+
- ${POLARIS_SERVER_ADDRESS:127.0.0.1:8091}
|
|
33
|
+
token: ${POLARIS_TOKEN:}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Use `Configuration.from_file()` for YAML, `Configuration.from_env()` for environment
|
|
37
|
+
variables, or `Configuration.from_dict()` for code-owned mappings. Python durations
|
|
38
|
+
are integer milliseconds; YAML also accepts values such as `500ms`, `1s`, and `1m30s`.
|
|
39
|
+
|
|
40
|
+
See:
|
|
41
|
+
|
|
42
|
+
- [Configuration parameters](docs/config/configuration-reference.md)
|
|
43
|
+
- [Minimal YAML example](docs/config/polaris.yaml)
|
|
44
|
+
- [Environment variables and precedence](docs/config/environment-variables.md)
|
|
45
|
+
- [Minimal file example](examples/sdkconfig/file/polaris.yaml)
|
|
46
|
+
|
|
47
|
+
## Context
|
|
48
|
+
|
|
49
|
+
Each `SDKContext` owns its configuration snapshot, client ID, plugins, connections,
|
|
50
|
+
caches, tasks, and logs. Reuse one context for APIs that should share that client.
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from polaris import Configuration, init_context_by_config
|
|
54
|
+
|
|
55
|
+
config = Configuration()
|
|
56
|
+
config.set_default()
|
|
57
|
+
config.get_global().get_server_connector().addresses = ["127.0.0.1:8091"]
|
|
58
|
+
|
|
59
|
+
context = init_context_by_config(config)
|
|
60
|
+
try:
|
|
61
|
+
...
|
|
62
|
+
finally:
|
|
63
|
+
context.destroy()
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
API calls after `destroy()` raise `SDKError`.
|
|
67
|
+
|
|
68
|
+
## Provider
|
|
69
|
+
|
|
70
|
+
`ProviderAPI` supports synchronous methods and `async_` counterparts.
|
|
71
|
+
`register_instance()` enables SDK-managed heartbeats by default.
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from polaris.pkg.model.server import InstanceRegisterRequest
|
|
75
|
+
|
|
76
|
+
response = provider.register_instance(InstanceRegisterRequest(
|
|
77
|
+
service="demo",
|
|
78
|
+
service_token="service-token",
|
|
79
|
+
namespace="default",
|
|
80
|
+
host="127.0.0.1",
|
|
81
|
+
port=8080,
|
|
82
|
+
ttl=5,
|
|
83
|
+
))
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The service token authorizes register, heartbeat, and deregister. It is different
|
|
87
|
+
from `POLARIS_TOKEN`, which authenticates the SDK connection.
|
|
88
|
+
|
|
89
|
+
Automatic re-registration runs after two consecutive `400202` responses and
|
|
90
|
+
`provider.minRegisterInterval`.
|
|
91
|
+
Deregistration stops heartbeat tasks before the RPC. Context destruction does not
|
|
92
|
+
implicitly deregister instances.
|
|
93
|
+
|
|
94
|
+
## Consumer
|
|
95
|
+
|
|
96
|
+
Reuse one `ConsumerAPI` per context. Synchronous calls are `get_one_instance()`,
|
|
97
|
+
`get_instances()`, `get_all_instances()`, `get_healthy_instances()`, and
|
|
98
|
+
`get_services()`; query methods have `async_` counterparts. `watch_service()` pins a
|
|
99
|
+
loaded resource and forwards cache lifecycle events; `unwatch_service()` releases it.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from polaris.pkg.model.service import GetOneInstanceRequest
|
|
103
|
+
|
|
104
|
+
instance = consumer.get_one_instance(GetOneInstanceRequest(
|
|
105
|
+
namespace="default",
|
|
106
|
+
service="demo",
|
|
107
|
+
))
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
After invoking the downstream service, report the result with
|
|
111
|
+
`update_service_call_result()` or `async_update_service_call_result()`.
|
|
112
|
+
|
|
113
|
+
Local cache behavior, idle eviction, disk retries, and restart recovery are covered by
|
|
114
|
+
the examples and [configuration reference](docs/config/configuration-reference.md).
|
|
115
|
+
|
|
116
|
+
## AI Registry
|
|
117
|
+
|
|
118
|
+
- MCP, A2A, and LangGraph use ordinary `Instance` registration and discovery.
|
|
119
|
+
- Service contracts use `report_service_contract()` and `get_service_contract()`.
|
|
120
|
+
- `SkillAPI` provides read-only get/list/download operations over an independent connector.
|
|
121
|
+
- Skill downloads can fall back to versioned local backups after network errors.
|
|
122
|
+
|
|
123
|
+
See [AI Registry APIs](docs/guides/ai-registry.md) and:
|
|
124
|
+
|
|
125
|
+
- [MCP example](examples/mcp/README.md)
|
|
126
|
+
- [A2A example](examples/a2a/README.md)
|
|
127
|
+
- [Skill example](examples/skill/README.md)
|
|
128
|
+
|
|
129
|
+
## Plugins
|
|
130
|
+
|
|
131
|
+
| Kind | Names |
|
|
132
|
+
| --- | --- |
|
|
133
|
+
| Server connector | `grpc` |
|
|
134
|
+
| Local cache | `inmemory`, `file` |
|
|
135
|
+
| Service router | `isolatedRouter`, `metadataRouter`, `recoverRouter` |
|
|
136
|
+
| Load balancer | `weightedRandom`, `random` |
|
|
137
|
+
| Circuit breaker | `composite` |
|
|
138
|
+
| Stat reporter | `prometheus` (`pushgateway` chain alias for push mode) |
|
|
139
|
+
| Event reporter | `pushgateway` |
|
|
140
|
+
|
|
141
|
+
Legacy names `wr` and `err_count` normalize to `weightedRandom` and `composite`.
|
|
142
|
+
Remote lossless rules are supported. Remote circuit-breaking, routing, rate-limiting and
|
|
143
|
+
configuration rules remain disabled, and active health detection is not enabled.
|
|
144
|
+
|
|
145
|
+
## Observability And Security
|
|
146
|
+
|
|
147
|
+
Public cloud currently uses Pushgateway as the default supported export path.
|
|
148
|
+
Prometheus pull remains available for self-hosted or custom scraping setups.
|
|
149
|
+
See [Observability](docs/guides/observability.md).
|
|
150
|
+
|
|
151
|
+
Each context has an isolated event center for implemented instance-cache and local
|
|
152
|
+
circuit-breaker events, with an optional Pushgateway reporter. See
|
|
153
|
+
[Events](docs/guides/events.md).
|
|
154
|
+
|
|
155
|
+
The registry and Skill connectors support independent TLS and mTLS certificates.
|
|
156
|
+
Invalid certificate configuration fails startup instead of falling back to plaintext.
|
|
157
|
+
See [TLS](docs/guides/tls.md).
|
|
158
|
+
|
|
159
|
+
## Examples
|
|
160
|
+
|
|
161
|
+
Run all offline verifications:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
./examples/verify_all.sh
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Run or inspect a single demo:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
cd examples/quickstart
|
|
171
|
+
./run.sh --help
|
|
172
|
+
./verify.sh
|
|
173
|
+
./logs.sh --latest --tail 30
|
|
174
|
+
./cleanup.sh --force
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Start with [examples/README.md](examples/README.md). Real registry examples require
|
|
178
|
+
`POLARIS_E2E=1`.
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
[BSD 3-Clause](LICENSE)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "polaris-python"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "Python SDK for Polaris service governance."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "BSD-3-Clause"
|
|
7
|
+
authors = [{ name = "evelynwei", email = "evelynwei@tencent.com" }]
|
|
8
|
+
keywords = ["polaris", "service-governance", "service-discovery", "service-mesh", "grpc"]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"Operating System :: OS Independent",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.12",
|
|
15
|
+
"Programming Language :: Python :: 3.13",
|
|
16
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
17
|
+
"Topic :: System :: Distributed Computing",
|
|
18
|
+
]
|
|
19
|
+
requires-python = ">=3.12"
|
|
20
|
+
dependencies = [
|
|
21
|
+
"grpcio>=1.84.0",
|
|
22
|
+
"protobuf>=7.35.1,<8",
|
|
23
|
+
"polarismesh-specification==1.9.0.dev4",
|
|
24
|
+
"PyYAML>=6.0.2,<7",
|
|
25
|
+
"psutil>=7.0,<8",
|
|
26
|
+
"prometheus-client>=0.21,<1",
|
|
27
|
+
"aiohttp>=3.11,<4",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/polaris-contrib/polaris-python"
|
|
32
|
+
Repository = "https://github.com/polaris-contrib/polaris-python"
|
|
33
|
+
Issues = "https://github.com/polaris-contrib/polaris-python/issues"
|
|
34
|
+
Documentation = "https://github.com/polaris-contrib/polaris-python#readme"
|
|
35
|
+
|
|
36
|
+
[dependency-groups]
|
|
37
|
+
dev = [
|
|
38
|
+
"pytest>=8.3,<9",
|
|
39
|
+
"pytest-asyncio>=0.24,<0.25",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[build-system]
|
|
43
|
+
requires = ["setuptools>=77", "wheel"]
|
|
44
|
+
build-backend = "setuptools.build_meta"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools]
|
|
47
|
+
packages = { find = { where = ["src"] } }
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.dynamic]
|
|
50
|
+
version = { attr = "polaris._version.__version__" }
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
asyncio_mode = "auto"
|
|
54
|
+
markers = [
|
|
55
|
+
"e2e: tests requiring a running Polaris service",
|
|
56
|
+
]
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Tencent is pleased to support the open source community by making polaris-python available.
|
|
2
|
+
#
|
|
3
|
+
# Copyright (C) 2021 Tencent. All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the BSD 3-Clause License (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# https://opensource.org/licenses/BSD-3-Clause
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software distributed
|
|
12
|
+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
13
|
+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
14
|
+
# specific language governing permissions and limitations under the License.
|
|
15
|
+
|
|
16
|
+
from polaris.api.config import (
|
|
17
|
+
SDKContext,
|
|
18
|
+
init_context,
|
|
19
|
+
init_context_by_config,
|
|
20
|
+
init_context_by_file,
|
|
21
|
+
init_context_by_stream,
|
|
22
|
+
)
|
|
23
|
+
from polaris.api.consumer import ConsumerAPI, ServiceWatch, create_consumer_by_config, create_consumer_by_file
|
|
24
|
+
from polaris.api.log import LogOptions
|
|
25
|
+
from polaris.api.lossless import LosslessAPI
|
|
26
|
+
from polaris.api.provider import ProviderAPI, create_provider_by_config, create_provider_by_file
|
|
27
|
+
from polaris.api.skill import (
|
|
28
|
+
SkillAPI,
|
|
29
|
+
create_skill_by_config,
|
|
30
|
+
create_skill_by_context,
|
|
31
|
+
create_skill_by_default_config_file,
|
|
32
|
+
create_skill_by_file,
|
|
33
|
+
)
|
|
34
|
+
from polaris.pkg.model.service import Instance
|
|
35
|
+
from polaris.pkg.model.event import EventCenter, SDKEvent, SDKEventName, SDKEventType
|
|
36
|
+
from polaris.pkg.model.lossless import InstanceProperties, LosslessActionProvider, LosslessInstance, RegisterStatus
|
|
37
|
+
from polaris.pkg.config.api import Configuration
|
|
38
|
+
from polaris.pkg.model.error import ErrorCode, SDKError
|
|
39
|
+
from polaris._version import __version__
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"Configuration",
|
|
43
|
+
"ConsumerAPI",
|
|
44
|
+
"ServiceWatch",
|
|
45
|
+
"ErrorCode",
|
|
46
|
+
"LogOptions",
|
|
47
|
+
"LosslessAPI",
|
|
48
|
+
"LosslessActionProvider",
|
|
49
|
+
"LosslessInstance",
|
|
50
|
+
"InstanceProperties",
|
|
51
|
+
"ProviderAPI",
|
|
52
|
+
"Instance",
|
|
53
|
+
"EventCenter",
|
|
54
|
+
"SDKEvent",
|
|
55
|
+
"SDKEventName",
|
|
56
|
+
"SDKEventType",
|
|
57
|
+
"SkillAPI",
|
|
58
|
+
"RegisterStatus",
|
|
59
|
+
"create_skill_by_config",
|
|
60
|
+
"create_skill_by_context",
|
|
61
|
+
"create_skill_by_default_config_file",
|
|
62
|
+
"create_skill_by_file",
|
|
63
|
+
"SDKContext",
|
|
64
|
+
"SDKError",
|
|
65
|
+
"create_consumer_by_config",
|
|
66
|
+
"create_consumer_by_file",
|
|
67
|
+
"create_provider_by_config",
|
|
68
|
+
"create_provider_by_file",
|
|
69
|
+
"init_context_by_config",
|
|
70
|
+
"init_context_by_file",
|
|
71
|
+
"init_context",
|
|
72
|
+
"init_context_by_stream",
|
|
73
|
+
"__version__",
|
|
74
|
+
]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Tencent is pleased to support the open source community by making polaris-python available.
|
|
2
|
+
#
|
|
3
|
+
# Copyright (C) 2021 Tencent. All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the BSD 3-Clause License (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# https://opensource.org/licenses/BSD-3-Clause
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software distributed
|
|
12
|
+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
13
|
+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
14
|
+
# specific language governing permissions and limitations under the License.
|
|
15
|
+
|
|
16
|
+
__version__ = "0.0.1.dev3"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Tencent is pleased to support the open source community by making polaris-python available.
|
|
2
|
+
#
|
|
3
|
+
# Copyright (C) 2021 Tencent. All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the BSD 3-Clause License (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# https://opensource.org/licenses/BSD-3-Clause
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software distributed
|
|
12
|
+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
13
|
+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
14
|
+
# specific language governing permissions and limitations under the License.
|
|
15
|
+
|
|
16
|
+
"""Public Polaris SDK APIs."""
|
|
17
|
+
|
|
18
|
+
from polaris.api.config import (
|
|
19
|
+
SDKContext,
|
|
20
|
+
init_context,
|
|
21
|
+
init_context_by_config,
|
|
22
|
+
init_context_by_file,
|
|
23
|
+
init_context_by_stream,
|
|
24
|
+
)
|
|
25
|
+
from polaris.api.consumer import ConsumerAPI, ServiceWatch, create_consumer_by_config, create_consumer_by_file
|
|
26
|
+
from polaris.api.log import LogOptions
|
|
27
|
+
from polaris.api.provider import ProviderAPI, create_provider_by_config, create_provider_by_file
|
|
28
|
+
from polaris.api.skill import (
|
|
29
|
+
SkillAPI,
|
|
30
|
+
create_skill_by_config,
|
|
31
|
+
create_skill_by_context,
|
|
32
|
+
create_skill_by_default_config_file,
|
|
33
|
+
create_skill_by_file,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"ConsumerAPI",
|
|
38
|
+
"ServiceWatch",
|
|
39
|
+
"LogOptions",
|
|
40
|
+
"ProviderAPI",
|
|
41
|
+
"SkillAPI",
|
|
42
|
+
"SDKContext",
|
|
43
|
+
"create_consumer_by_config",
|
|
44
|
+
"create_consumer_by_file",
|
|
45
|
+
"create_provider_by_config",
|
|
46
|
+
"create_provider_by_file",
|
|
47
|
+
"create_skill_by_config",
|
|
48
|
+
"create_skill_by_context",
|
|
49
|
+
"create_skill_by_default_config_file",
|
|
50
|
+
"create_skill_by_file",
|
|
51
|
+
"init_context_by_config",
|
|
52
|
+
"init_context_by_file",
|
|
53
|
+
"init_context",
|
|
54
|
+
"init_context_by_stream",
|
|
55
|
+
]
|