Skip to main content

A python nacos client based on the official open-api

Project description

use-nacos

Test Package version Supported Python versions

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.6.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

use_nacos-0.1.6-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file use_nacos-0.1.6.tar.gz.

File metadata

  • Download URL: use_nacos-0.1.6.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.18 Linux/6.11.0-1015-azure

File hashes

Hashes for use_nacos-0.1.6.tar.gz
Algorithm Hash digest
SHA256 39fd209d6719d5a554bf5f365668042199ab80d03f95d3829c0f79c077ca3c49
MD5 b8e3093c415cacf49a55775aa16621b6
BLAKE2b-256 1eb376c66910f082f73da38f29b6d75a5f152479b16e4a6e1a815aea1da3421d

See more details on using hashes here.

File details

Details for the file use_nacos-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: use_nacos-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.18 Linux/6.11.0-1015-azure

File hashes

Hashes for use_nacos-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7b738918c82f2f2197b9949fac55216dd9aa4ab0648d168964d212a0d64a67ac
MD5 aadc80dcc827eed3ede6ee920c4ae604
BLAKE2b-256 bd9ad4d69b6446431304c13912aa98cc03f7ba52ac01efb80de66cdf1b3923dc

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