Easy to use gRPC-web client in python

Related tags

Networkingpyease-grpc
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
Apple Store Stock Notifier monitors the availability of selected Apple devices in selected Apple stores, and sends you a notification when devices are available!

Apple Store Stock Notifier This software will immediately send you a notification via Telegram when one of your coveted Apple Devices is available in

Floris-Jan Willemsen 25 Dec 05, 2022
Simple P2P application for sending files over open and forwarded network ports.

FileShareV2 A major overhaul to the V1 (now deprecated) FileShare application. V2 brings major improvements in both UI and performance. V2 is now base

Michael Wang 1 Nov 23, 2021
A simple GitHub Action that physically puts your senses on alert when your build/release fails

GH Release Paniker A simple GitHub Action that physically puts your senses on alert when your build/release fails Usage Requirements: Raspberry Pi, LE

Hemanth Krishna 5 Dec 20, 2021
A Python module that allows you to create and use simple sockets.

EasySockets A Python module that allows you to create and use simple sockets. Installation The easysockets module can be installed using pip. pip inst

Matthias Wijnsma 2 Jan 16, 2022
A Python server and client app that tracks player session times and server status

MC Outpost A Python server and client application that tracks player session times and server status About MC Outpost provides a session graph and ser

Grant Scrits 0 Jul 23, 2021
IP-Escaner - A Python Tool to obtain information from an IP address

IP-Escaner Herramienta para obtener informacion de una direccion IP Opciones de

4 Apr 09, 2022
Utility for converting IP Fabric webhooks into a Teams format.

IP Fabric Webhook Integration for Microsoft Teams and/or Slack Setup IP Fabric Setup Go to Settings Webhooks Add webhook Provide a name URL will b

Community Fabric 1 Jan 26, 2022
An API for controlling Wi-Fi connections on Balena devices.

Description An API for controlling Wi-Fi connections on Balena devices. It does not contain an interface, instead it provides API endpoints to send re

8 Dec 25, 2022
A website to list Shadowsocks proxies and check them periodically

Shadowmere An automatically tested list of Shadowsocks proxies. Motivation Collecting proxies around the internet is fun, but what if they stop workin

Jorge Alberto Díaz Orozco (Akiel) 29 Dec 21, 2022
StarCraft II Client - protocol definitions used to communicate with StarCraft II.

Overview The StarCraft II API is an interface that provides full external control of StarCraft II. This API exposes functionality for developing softw

Blizzard Entertainment 3.6k Dec 30, 2022
Geowifi 📡 💘 🌎 Search WiFi geolocation data by BSSID and SSID on different public databases.

Geowifi 📡 💘 🌎 Search WiFi geolocation data by BSSID and SSID on different public databases.

GOΠZO 441 Dec 23, 2022
stellar-add-guest is a small tool to generate a new guest for Stellar Wireless (Enterprise mode) in OmniVista 2500 hosted on OmniSwitch with AOS Release 8

stellar-add-guest is a small tool to generate a new guest for Stellar Wireless (Enterprise mode) in OmniVista 2500 hosted on OmniSwitch with AOS Release 8.

BennyE 3 Jan 24, 2022
Implementing Cisco Support APIs into NetBox

NetBox Cisco Support API Plugin NetBox plugin using Cisco Support APIs to gather EoX and Contract coverage information for Cisco devices. Compatibilit

Timo Reimann 23 Dec 21, 2022
wireguard-config-benchmark is a python script that benchmarks the download speeds for the connections defined in one or more wireguard config files

wireguard-config-benchmark is a python script that benchmarks the download speeds for the connections defined in one or more wireguard config files. If multiple configs are benchmarked it will output

Sal 12 May 07, 2022
Serves some data over HTTP, once. Based on the built-in Python module http.server

serve-me-once Serves some data over HTTP, once. Based on the built-in Python module http.server.

Peder Bergebakken Sundt 2 Jan 06, 2022
Base on browser-time to get har from network, and use python to analyze the data .

base on browser-time to get har from network, and use python to analyze the data

1 Dec 20, 2021
Easily share folders between VMs.

This package aims to solve the problem of inter-VM file sharing (rather than manual copying) by allowing a VM to mount folders from any other VM's file system (or mounted network shares).

Rudd-O 12 Oct 17, 2022
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.

Miss Bliss 1 Nov 13, 2021
A great python/java dynamic DNS service for NameSilo, with log, email reminder...

English NameSilo DDNS is a DDNS service for NameSilo domain names for home broadband , it can automatically detect IP changes in home broadband

云牧青 77 Dec 28, 2022
ASC - Api Server Controller

ASC - Api Server Controller

Uriel Alves 1 Jan 03, 2022