Skip to main content

娱网科道内部python 公用包

安装

使用 pip 安装

$ pip install ywkd_tools

pip 地址

https://pypi.org/project/ywkd-tools/

使用

PRC 调用

from ywkd_tools.inner_service_apis import InnerServices
InnerServices.setup(service_name=<调用者名称>, base_url=<RPC Domain>, secret=<RPC 认证密码>)

# 发送短信
InnerServices.MSG().send_sms([57], 'SMS_177552091', {'username': 'tester','password': 'pwd12345'})

# 用户过滤
InnerServices.Cperm().filter_users(group_codes__in=['ceo'])

# 调用自定义方法 fun
InnerServices.Cperm().rpc_client.fun(...)

# 获取用户详情
InnerServices.Cperm().get_user(1)

# 实例1:
class AViewOrSerializer(xxx):
    def some_method(...):
        cperm = InnerServices.Cperm()
        cperm.get_user(...)
        cperm.filter_users(...)
        cperm.rpc_client.fun(...)
        ...

# 实例2:
@app.task(...)
def asyn_job(...):
    cperm = InnerServices.Cperm(request_id='xxxxxxxxxx') # or cperm = InnerServices.Cperm(request=request)
    cperm.get_user(...)
    cperm.filter_users(...)
    cperm.rpc_client.fun(...)
    ...

Auth 认证

# 在初始化文件中执行
from ywkd_tools.auth import Auth
Auth.setup(service_name=<调用者名称>, rpc_base_url=<RPC Domain>, rpc_secret=<RPC 认证密码>)


# 在django view文件中
from ywkd_tools.auth import Auth

class SomeView(BaseView):
    """需要认证的Django Vew"""

    authentication_classes = [Auth.RSTFBasciAuthentication]
    ...

    def get(self, request, *args, **kwargs):
        return self.list(request, *args, **kwargs)

    def post(self, request, *args, **kwargs):
        return self.create(request, *args, **kwargs)


# 在对外提供RPC服务的文件中
from modernrpc.core import rpc_method
from modernrpc.auth import set_authentication_predicate
from ywkd_tools.auth import Auth

@rpc_method
def ping():
    """不需要认证的rpc 接口"""
    return 'pong'

@rpc_method
@set_authentication_predicate(Auth.RPCBasciAuthentication().authenticate)
def get_import_info():
    """需要认证的rpc 接口"""
    return ...

发布包

# 确保您拥有setuptools并wheel 安装了最新版本
$ python3 -m pip install --upgrade setuptools wheel

# 安装Twine
$ python3 -m pip install --upgrade twine

# 从setup.py位于的同一目录运行此命令
$ python3 setup.py sdist bdist_wheel

# 运行Twine以上传所有存档dist
$ python3 -m twine upload dist/*
$ python3 -m twine upload --skip-existing dist/*

Metadata

Release files for ywkd-tools 1.0.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ywkd-tools 1.0.18
File Size Uploaded
ywkd_tools-1.0.18.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ywkd-tools 1.0.18
File Interpreter ABI Platform
ywkd_tools-1.0.18-py3-none-any.whl Python 3 none any Details

Total release size: 24.3 kB

Release files / ywkd_tools-1.0.18.tar.gz

Download URL ywkd_tools-1.0.18.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
63cbfb829eba0078e849a8761922d7c57a36014baee46c999e86d0478e17e3f1
BLAKE2b-256 checksum
How to use checksums
8654b63eddb46c87c77d855f9c631adc8d417d82220900df155799fad536dea1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

Release files / ywkd_tools-1.0.18-py3-none-any.whl

Download URL ywkd_tools-1.0.18-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfb5ab36d0064ce559c99e2186345d5bcc01cbb86f8122283916116991abf0f3
BLAKE2b-256 checksum
How to use checksums
d97392b5baeff4bc0d9a6832abce66cd81e54c5736298601884fb5dd30497cb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

1.0.18 This release

2 release files

1.0.16

2 release files

1.0.15

2 release files

1.0.14

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page