Skip to main content

A python nacos client based on the official open-api

Project description

nacos-py-client

Test Package version Supported Python versions

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", "namespaceId") == "test_value"


# subscribe config

def config_update(config):
    print(config)


client.config.subscribe(
    "test_config",
    "DEFAULT_GROUP",
    "namespaceId",
    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.5.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nacos_py_client-0.2.5-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file nacos_py_client-0.2.5.tar.gz.

File metadata

  • Download URL: nacos_py_client-0.2.5.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for nacos_py_client-0.2.5.tar.gz
Algorithm Hash digest
SHA256 79515ba05ea74b5f57aad93cb72efda30395db1a3e055dc7a9c2833cb0c68238
MD5 5e96b35af0f0cff4c605e70956ed417a
BLAKE2b-256 d6766e9fc32daaa48ba48d2f650a507a7005bfc0a0e377f7393001ecf0885da3

See more details on using hashes here.

File details

Details for the file nacos_py_client-0.2.5-py3-none-any.whl.

File metadata

File hashes

Hashes for nacos_py_client-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 00a4e231e0d6d301d8883e2284bf2db007bbb6ea15301bdcf23a598d54ae841e
MD5 a6569305396d74efdb8c2d8d9024a0b3
BLAKE2b-256 f3a9e04ae4b547e58510c690ac290633f5bb513faaea9313c97a263168b8bc98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page