Coder Social home page Coder Social logo

dengliming / incubator-shenyu-client-python Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apache/shenyu-client-python

1.0 1.0 0.0 45 KB

Apache ShenYu Client SDK for python.

Home Page: https://shenyu.apache.org/

License: Apache License 2.0

Python 100.00%

incubator-shenyu-client-python's Introduction

Apache-ShenYu-Client

Apache-Shenyu-Client for python client allows you to access ShenYu Gateway, it supports registory python service to ShenYu Gateway.

Requirements

Supported python version over 3.6 Supported ShenYu version over 2.4.3

instructions

1、install
pip3 install Apache-ShenYu-Client -i https://pypi.python.org/simple

2、usage

3.1、Use the decorator

>>import package:      

from apache_shenyu_client.config import GatewayConfig
from apache_shenyu_client.register import register_uri, register_metadata, register_all_metadata

3.1.0、First, modify the configuration according to the project situation, If you do not configure it, you will not be able to use apache_shenyu_client.   
#### Configure shenyu gateway services and port 
GatewayConfig.test = {
        "servers": "xx.xx.xx.xx",
        "port": 1001
    }   
#### Configure python services information   
GatewayConfig.uri = {
        "app_name": "app2",             # app name
        "host": "172.24.43.28",         # python service host
        "port": 8000,                   # python service port
        "context_path": "/flask_test",   # context_path
        "environment": "test",          # environment
        "rpc_type": "http"              # rpc type
    }       
#### Configure to get administrator token
GatewayConfig.register = {
        "register_type": "http",
        "servers": "xx.xx.xx.xx",
        "props": {
            "username": "admin",
            "password": "123456"
        }
    }

3.1.1、proxy all api

3.1.1.1、Using a decorator at the entry of a service request to register for this service: @register_uri 
3.1.1.2、Using a decorator at the entry of a service request: @register_all_metadata(register_all=True)

3.1.2、proxy some api
3.1.2.1、Using a decorator at the entry of a service request to register for this service: @register_uri 
3.1.2.2、use a decorator on that api definition: @register_metadata,need param: path, as follows 3.1.2.3:

3.1.2.3、this is a python flask service api, path is "/search"
    @user.route('/search', methods=['GET'])
    def user_search_handler():
        data = UserBusiness.search_by_nickname()
        return json_detail_render(0, data)`

proxy:
@register_metadata("/search")
@user.route('/search', methods=['GET'])
def user_search_handler():
    data = UserBusiness.search_by_nickname()
    return json_detail_render(0, data)

3.2、function call usage

>>import package

from apache_shenyu_client.config import GatewayConfig
from apache_shenyu_client.api import GatewayProxy
gt = GatewayProxy()

3.2.1、Modify the configuration according to the project situation
GatewayConfig.uri = {
        "app_name": "app2",            # app name
        "host": "172.24.43.28",        # python service host
        "port": 8000,                  # python service port
        "context_path": "/flask_test",  # context_path
        "environment": "test",         # environment
        "rpc_type": "http"             # rpc type
    }

3.2.2、register uri: gt.register_uri()

"/helloqq2" is the path to register  

3.2.2.1、register some path:   
gt.register_metadata("/helloqq2")

3.2.2.1、register all path:   
gt.register_metadata(register_all=True)

incubator-shenyu-client-python's People

Contributors

mutianzero avatar tuohai666 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.