A python nacos client based on the official open-api
Project description
nacos-py-client
A python nacos client based on the official open-api.
install
pip install nacos-py-client
usage
config
from nacos_py_client import NacosClient
client = NacosClient(...)
# publish config
client.config.publish("test_config", "DEFAULT_GROUP", "test_value")
# get config
assert client.config.get("test_config", "DEFAULT_GROUP") == "test_value"
# subscribe config
def config_update(config):
print(config)
client.config.subscribe(
"test_config",
"DEFAULT_GROUP",
callback=config_update
)
instance
from nacos_py_client import NacosClient
nacos = NacosClient()
nacos.instance.register(
service_name="test",
ip="10.10.10.10",
port=8000,
weight=10.0
)
nacos.instance.heartbeat(
service_name="test",
ip="10.10.10.10",
port=8000,
)
😘support async mode
# example: fastapi
from contextlib import asynccontextmanager
import uvicorn
from fastapi import FastAPI
from nacos_py_client import NacosAsyncClient
def config_update(config):
print(config)
@asynccontextmanager
async def lifespan(app: FastAPI):
nacos = NacosAsyncClient()
config_subscriber = await nacos.config.subscribe(
data_id="test-config",
group="DEFAULT_GROUP",
callback=config_update,
)
yield
config_subscriber.cancel()
app = FastAPI(lifespan=lifespan)
if __name__ == '__main__':
uvicorn.run("in_fastapi:app", host="0.0.0.0", port=1081)
Developing
make install # Run `poetry install`
make lint # Runs bandit and black in check mode
make format # Formats you code with Black
make test # run pytest with coverage
make publish # run `poetry publish --build` to build source and wheel package and publish to pypi
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nacos_py_client-0.2.1.tar.gz
(9.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nacos_py_client-0.2.1.tar.gz.
File metadata
- Download URL: nacos_py_client-0.2.1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4df1b893ccef285bca03acef3f73a324aa3a0a8e35ee61bc712c9e5640ed23d
|
|
| MD5 |
fefcb217554f85cf2b3902326807c7e9
|
|
| BLAKE2b-256 |
151b8a4201305e9e2e0f6e97c95caa3e0f97915674bc4372f054b757fc83a39f
|
File details
Details for the file nacos_py_client-0.2.1-py3-none-any.whl.
File metadata
- Download URL: nacos_py_client-0.2.1-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45b5d05b09d3a9cc6cf2c2039c5c6a5d282610f6fea7a292b8023733c42c0b10
|
|
| MD5 |
69e7c88eff5940119a35a661ff755c8b
|
|
| BLAKE2b-256 |
d3a3c80f50372f37c2f2f032d998c704475430cc935235e91aec72b579092fd7
|