Skip to main content

A framework of remote procedure call.

Project description

arpc

A framework of remote procedure call.

Quick Start

arpc

# ${project}/arpc/api.arpc
arpc: 1.0

package {
    python: api
    go: api
}

procedures {
    procedure GetUserV1(RequestV1): ResponseV1
}

param RequestV1 {
    UserId: integer = 1
}

param ResponseV1 {
    UserId: integer = 1
    Username: string = 2
}

Compile

arpc -i ./arpc_file -o ./arpc_package -a true

Server

from arpc.server import Server

from arpc_package.api.api import Arpc, RequestV1, ResponseV1


class S(Arpc):

    def get_user_v1(self, request: RequestV1) -> ResponseV1:
        print(request)
        return ResponseV1(user_id=1, username='arpc name')

    def post_user_v1(self, request: ResponseV1) -> RequestV1:
        print(request)
        return RequestV1(user_id=1)


def start():

    s = Server('127.0.0.1', 9000)

    c = S()
    c.register(s)

    s.start()


if __name__ == '__main__':
    start()

Server Async

require package: nest-asyncio >= 1.5.6

from arpc.server import ServerAsync

from arpc_package.api.api import Arpc, RequestV1, ResponseV1


class S(Arpc):

    async def get_user_v1(self, request: RequestV1) -> ResponseV1:
        print(request)
        return ResponseV1(user_id=1, username='arpc name')

    async def post_user_v1(self, request: ResponseV1) -> RequestV1:
        print(request)
        return RequestV1(user_id=1)


async def start():

    s = ServerAsync('127.0.0.1', 9000)

    c = S()
    await c.register(s)

    await s.start()


if __name__ == '__main__':
    asyncio.run(start_async())

Client

import asyncio
from arpc.client import new_arpc_conn, new_arpc_conn_async
from arpc_package.api.api import Client, RequestV1


async def main_async():
    conn = await new_arpc_conn_async("127.0.0.1", 9000)
    client = Client(conn)
    request = RequestV1(user_id=1)
    response = await client.get_user_v1(request)
    print(await response.json())


def main():
    conn = new_arpc_conn("127.0.0.1", 9000)
    client = Client(conn)
    request = RequestV1(user_id=1)
    response = client.get_user_v1(request)
    print(response.json())


if __name__ == '__main__':
    # main()
    asyncio.run(main_async())

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

arpc-0.1.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

arpc-0.1.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file arpc-0.1.0.tar.gz.

File metadata

  • Download URL: arpc-0.1.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.12.0a2+

File hashes

Hashes for arpc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1b353b66c67c41bb52345680c6aeaa8da15e186483f2a654123528e19535710b
MD5 c1489bb438d1ca26ded3023586f7ff83
BLAKE2b-256 e585a75e1e3d96150e78cde30bf1f208a3dbe54013a7ceec8474fa060fda0b0a

See more details on using hashes here.

File details

Details for the file arpc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: arpc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.12.0a2+

File hashes

Hashes for arpc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4269769a97f323a126d5f8940f237f21d21258b3d6efa3a04b03a1b847998ff5
MD5 ee2bd31daa4ff62597dcd264b17f566e
BLAKE2b-256 355b12274158ce5664a196fc3c5f070aa71a8581cb702ccc1989b849ca43aa00

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page