Skip to main content

anthunder(a.k.a. sofa-bolt-python)

anthunder(ant thunder) is a sofa-bolt library written in python. It supports RPC calling via 'sofa-bolt + protobuf' protocol.

requirements

  • python3 >= 3.5 (aio classes needs asyncio support)
  • python2.7 (limited support, needs extra 3rd party libraries)
  • mosn >= 1.3 (to use with version >= 0.6)
  • mosn < 1.3 (to use with version < 0.6)

roadmap

  • bolt client(protobuf serialization)
  • service discover via mosn (sofa servicemesh sidecar)
  • bolt server(protobuf serialization)
  • hessian2 serialization support

Tutorial

As client (caller)

  1. Acquire .proto file
  2. Execute protoc --python_out=. *.proto to compile protobuf file, and get _pb2.py file.
  3. Import protobuf classes (postfixed with _pb2)
from SampleServicePbResult_pb2 import SampleServicePbResult
from SampleServicePbRequest_pb2 import SampleServicePbRequest

from anthunder import AioClient


spanctx = SpanContext()         # generate a new context, an object of mytracer.SpanContext, stores rpc_trace_context.
# spanctx = ctx                 # or transfered from upstream rpc
client = AioClient(my_app_name) # my_app_name will be send to sidecar as caller name.
                                # will create a thread, and send heartbeat to mesh every 30s

interface = 'com.alipay.rpc.common.service.facade.pb.SampleServicePb:1.0'

# Subscribe interface
client.subscribe(interface)

# Call synchronously
content = client.invoke_sync(interface, "hello",
                             SampleServicePbRequest(name=some_name).SerializeToString(),
                             timeout_ms=500, spanctx=spanctx)
result = SampleServicePbResult()
result.ParseFromString(content)

# Call asynchronously

def client_callback(resp):
    # callback function, accepts bytes as the only argument,
    # then do deserialize and further processes
    result = SampleServicePbResult()
    result.ParseFromString(content)
    # do something

future = client.invoke_async(interface, "hello", 
                             SampleServicePbRequest(name=some_name).SerializeToString(),
                             spanctx=spanctx, callback=client_callback)
)

See project's unittest for runnable demo

As server

from anthunder.listener import aio_listener

class SampleService(object):
    def __init__(self, ctx):
        # service must accept one param as spanctx for rpc tracing support
        self.ctx = ctx

    def hello(self, bs: bytes):
        obj = SampleServicePbRequest()
        obj.ParseFromString(bs)
        print("Processing Request", obj)
        return SampleServicePbResult(result=obj.name).SerializeToString()


listener = aio_listener.AioListener(('127.0.0.1', 12200), "test_app")
# register interface and its function, plus its protobuf definition class
listener.handler.register_interface("com.alipay.rpc.common.service.facade.pb.SampleServicePb:1.0",
                                    SampleService)
# start server in a standalone thread
listener.run_threading()
# or start in current thread
listener.run_forever()

# publish interfaces to service mesh
listener.publish()

# shutdown the server
listener.shutdown()

License

Copyright (c) 2018-present, Ant Financial Service Group

Apache License 2.0

See LICENSE file.

Thirdparty

Part of the mysockpool package uses codes from urllib3 project under the term of MIT License. See origin-license.txt under the mysockpool package.

Release History

0.5.6 (2019-03-15)

Bugfixes

  • fix a infinite loop bug when parsing protocol

0.5.4 (2018-11-09)

Bugfixes

  • fix server errors under python2.7

0.5.3 (2018-08-27)

Feature

  • support antsharecloud parameters.

0.5.2 (2018-09-03)

Bugfixes

  • fix various errors under python2.7

0.5.1 (2018-08-31)

Bugfixes

  • sofa trace rpc id may contains str.

Metadata

Release files for anthunder 0.8.1

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

Source distribution (sdist)

Source distribution for anthunder 0.8.1
File Size Uploaded Provenance
anthunder-0.8.1.tar.gz 35.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for anthunder 0.8.1
File Interpreter ABI Platform
anthunder-0.8.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 98.3 kB

Release files / anthunder-0.8.1.tar.gz

Download URL anthunder-0.8.1.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
324a318a3c3e88bfca46757c0cc39ebb45d24d5311341e31c0d8e679df98d75f
BLAKE2b-256 checksum
How to use checksums
483c30d2ef67cd8d6c075c830be899af3357d84333c4129c4a9b1a8acc339244
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

Release files / anthunder-0.8.1-py2.py3-none-any.whl

Download URL anthunder-0.8.1-py2.py3-none-any.whl
Size 62.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0e6857ca649816d178055de2216908bebda24d4a9852188d0298e34c32c775ad
BLAKE2b-256 checksum
How to use checksums
66a5698a507e1d7fa27a99c4a41e6a8796cf922f296e858bf6cd5e3d14567d9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

Security for anthunder 0.8.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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