Easy to use gRPC-web client in python

Overview

pyease-grpc

Build Release PyPI version Python version GitHub License

Easy to use gRPC-web client in python

Tutorial

This package provides a requests like interface to make calls to gRPC-Web servers.

Installation

Install the package using:

$ pip install pyease-grpc

Run the following to check if it has been installed correctly:

$ pyease-grpc --version

Introduction

To use it, you need to have a basic understanding of how gRPC works.

Let's run the server first. There is an example project here: https://github.com/dipu-bd/grpc-web-example

Clone it and follow the instructions on the README.md to start the server.

Let' check the example folder for the time_service.proto file:

// file: time_service.proto
syntax = "proto3";

package smpl.time.api.v1;

option go_package = "github.com/kostyay/grpc-web-example/api/time/v1";

message GetCurrentTimeRequest {
}

message GetCurrentTimeResponse {
  string current_time = 1;
}

service TimeService {
  rpc GetCurrentTime(GetCurrentTimeRequest) returns (GetCurrentTimeResponse);
}

Suppose the gRPC web server is running at http://localhost:8080.

To make a request to GetCurrentTime:

from pyease_grpc import Protobuf, RpcSession
from pyease_grpc.rpc_uri import RpcUri

protobuf = Protobuf.from_file('time_service.proto')
session = RpcSession(protobuf)

response = session.request(
    RpcUri('http://localhost:8080', package='smpl.time.api.v1',
           service='TimeService', method='GetCurrentTime'),
    {},
)
response.raise_for_status()

result = response.single
print(result['currentTime'])

The session.request accepts a dict as input and returns the response as dict.

Descriptor

A more convenient way to use the client is directly using the FileDescriptorSet.

To generate FileDescriptorSet as json:

$ pyease-grpc -I example example/time_service.proto --output example/descriptor.json

Now you can use this descriptor file directly to create Protobuf instance.

import json

with open('descriptor.json', 'r') as f:
  descriptor = json.load(f)

# Use the descriptor directly to create protobuf instance
protobuf = Protobuf.restore(descriptor)

# You can even create the session directly
session = RpcSession.from_descriptor(descriptor)
You might also like...
Qobuz-rpc - A simple discord rich presence client for qobuz written in Python

qobuz-rpc A simple discord rich presence client for qobuz written in Python It's

Pywbem - A WBEM client and related utilities, written in pure Python.
Pywbem - A WBEM client and related utilities, written in pure Python.

Pywbem - A WBEM client and related utilities, written in pure Python Overview Pywbem is a WBEM client and WBEM indication listener and provides relate

A simple multi-threaded time server and client in python.

time-server-client A simple multi-threaded time server and client in Python. This uses the latest match/case command found in Python 3.10 so requires

(A)sync client for sms.ru with pydantic responses

🚧 aioSMSru Send SMS Check SMS status Get SMS cost Get balance Get limit Get free limit Get my senders Check login/password Add to stoplist Remove fro

A Simplest TCP client and echo server
A Simplest TCP client and echo server

Простейшие TCP-клиент и эхо-сервер Цель работы Познакомиться с приемами работы с сетевыми сокетами в языке программирования Python. Задания для самост

API to establish connection between server and client

Socket-programming API to establish connection between server and client, socket.socket() creates a socket object that supports the context manager ty

Simple client for the Sirah Matisse Commander TCP server.

Simple client for the Sirah Matisse Commander TCP server.

NanoChat - nano chat server and client
NanoChat - nano chat server and client

NanoChat This is a work in progress! NanoChat is an application for connecting with your friends using Python that uses ONLY default Python libraries.

Secure connection between tenhou Window client and server.

tenhou-secure The tenhou Windows client looks awesome. However, the traffic between the client and tenhou server is NOT encrypted, including your uniq

Comments
  • Does this lib support streaming RPCs?

    Does this lib support streaming RPCs?

    I already use this lib with simple RPCs, but now I also need to use streaming RPCs, so I'd like to know if they are already supported and if yes, how to use them in Python code.

    opened by sieberst 4
  • If i add

    If i add "Usera-agent" header, i have 2 "User-agent"

        user_agent = "grpc-web-javascript/0.1"
        headers = {
            "User-agnet": user_agent
        }
        response = session.request(
            RpcUri(url, package=package,
                   service=service, method=method),
            headers=headers,
            data=data
    
    Screenshot 2022-11-28 at 10 52 20

    It's problem for my api

    opened by fleytman 2
Owner
Sudipto Chandra
Software Engineer | ❤️s Python, Flutter, Spring Boot, Vue & Typescript.
Sudipto Chandra
league-connection is a python package to communicate to riot client and league client

league-connection is a python package to communicate to riot client and league client.

Sandbox 1 Sep 13, 2022
Client library for relay - a service for relaying server side messages to the client side browsers via websockets.

Client library for relay - a service for relaying server side messages to the client side browsers via websockets.

getme 1 Nov 10, 2021
This is a Client-Server-System which can share the screen from the server to client and in the other direction.

Screenshare-Streaming-Python This is a Client-Server-System which can share the screen from the server to client and in the other direction. You have

VFX / Videoeffects Creator 1 Nov 19, 2021
This is a Client-Server-System which can send audio from a microphone from the server to client and in the other direction.

Audio-Streaming-Python This is a Client-Server-System which can send audio from a microphone from the server to client and in the other direction. You

VFX / Videoeffects Creator 0 Jan 5, 2023
Very simple FTP client, sync folder to FTP server, use python, opensource

ftp-sync-python Opensource, A way to safe your data, avoid lost data by Virus, Randsomware Some functions: Upload a folder automatically to FTP server

null 4 Sep 13, 2022
Easy-to-use sync library for handy proxy parse

Proxy Parser About Synchronous library, for convenient and fast parsing of proxies from different sources. Uses Scrapy as a parser. At the moment the

Michael Mironov 2 Nov 22, 2022
A web-based app that allows easy, simple - and if desired high-throughput - analysis of qPCR data

qpcr-Analyser A web-based GUI for the qpcr package that allows easy, simple and high-throughput analysis of qPCR data. As is described in more detail

null 1 Sep 13, 2022
Python Scrcpy Client - allows you to view and control android device in realtime

Python Scrcpy Client This package allows you to view and control android device in realtime. Note: This gif is compressed and experience lower quality

LengYue 126 Jan 2, 2023
A python socket.io client for Roboteur

Roboteur Client Example TODO Basic setup Install the requirements: $ pip install -r requirements.txt Run the application: $ python -m roboteur_client

Barry Buck 1 Oct 13, 2021
A simple DHCP server and client simulation with python

About The Project This is a simple DHCP server and client simulation. I implemented it for computer network course spring 2021 The client can request

shakiba 3 Feb 8, 2022