Skip to main content

an(t)thunder is a sofa-bolt protocol lib.

Project description

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.


  • 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)


  • <input type="checkbox" checked="" disabled="" /> bolt client(protobuf serialization)
  • <input type="checkbox" checked="" disabled="" /> service discover via mosn (sofa servicemesh sidecar)
  • <input type="checkbox" checked="" disabled="" /> bolt server(protobuf serialization)
  • <input type="checkbox" disabled="" /> hessian2 serialization support


As client (caller)

  1. Acquire .proto file
  2. Execute protoc --python_out=. *.proto to compile protobuf file, and get 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 = ''

# Subscribe interface

# Call synchronously
content = client.invoke_sync(interface, "hello",
                             timeout_ms=500, spanctx=spanctx)
result = SampleServicePbResult()

# Call asynchronously

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

future = client.invoke_async(interface, "hello", 
                             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()
        print("Processing Request", obj)
        return SampleServicePbResult(

listener = aio_listener.AioListener(('', 12200), "test_app")
# register interface and its function, plus its protobuf definition class
# start server in a standalone thread
# or start in current thread

# publish interfaces to service mesh

# shutdown the server


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

Apache License 2.0

See LICENSE file.


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)


  • fix a infinite loop bug when parsing protocol

0.5.4 (2018-11-09)


  • fix server errors under python2.7

0.5.3 (2018-08-27)


  • support antsharecloud parameters.

0.5.2 (2018-09-03)


  • fix various errors under python2.7

0.5.1 (2018-08-31)


  • sofa trace rpc id may contains str.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for anthunder, version 0.8.1
Filename, size File type Python version Upload date Hashes
Filename, size anthunder-0.8.1-py2.py3-none-any.whl (62.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size anthunder-0.8.1.tar.gz (35.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page