Skip to main content

A toolkit for implementing tRPC servers in python

Project description

trpc-core

Toolkit for implementing tRPC servers in python

trpc-core is currently in prototype stage. You are welcome to play with the code or drop feedback in issues, just don't expect anything usable or functional yet.

Example tRPC API with Flask:

import trpc
from flask import Flask, jsonify, request


class Router(trpc.Router):
    @trpc.query(name="helloWorld")
    def hello_world(context) -> str:
        return "Hello world"

    @trpc.mutation(name="sum")
    def sum(context, *, a: int, b: int) -> int:
        return a + b


server = trpc.Server(Router)


app = Flask(__name__)


@app.route("/trpc/<path:path>", methods=["GET"])
def trpc_query(path):
    result = server.query(path)
    return jsonify(result)


@app.route("/trpc/<path:path>", methods=["POST"])
def trpc_mutation(path):
    result = server.mutation(path)
    return jsonify(result)

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

trpc_core-0.1.0.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

trpc_core-0.1.0-py2.py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 2 Python 3

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