A python nacos client based on the official open-api
Project description
use-nacos
A python nacos client based on the official open-api.
install
pip install use-nacos
usage
config
from use_nacos 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 use_nacos 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 use_nacos 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
use_nacos-0.1.5.tar.gz
(10.1 kB
view hashes)
Built Distribution
use_nacos-0.1.5-py3-none-any.whl
(13.2 kB
view hashes)
Close
Hashes for use_nacos-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d64174b8cc9500918669bb3c31a73e29f1f8ea462f4768f9c795190b9cfbe10b |
|
MD5 | 17ceb19276d43fe000f564ec5108b620 |
|
BLAKE2b-256 | cc9c197db8ddee085fe6d630ac29f34116a34e4334ab3dd05aeecb280418b328 |