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
Extended refactoring capabilities for Python LSP Server using Rope.

pylsp-rope Extended refactoring capabilities for Python LSP Server using Rope. This is a plugin for Python LSP Server, so you also need to have it ins

36 Dec 24, 2022
Cobalt Strike script for ScareCrow payloads

🎃 🌽 ScareCrow Cobalt Strike intergration CNA A Cobalt Strike script for ScareCrow payload generation. Works only with the binary and DLL Loader. 💣

UserX 401 Dec 11, 2022
TunnelProxy 是一个本地隧道代理,可以从fofa爬取免费的socks代理,然后构建代理池,如果一个代理失效,会自动切换

TunnelProxy 是一个本地隧道代理,可以从fofa爬取免费的socks代理,然后构建代理池,如果一个代理失效,会自动切换。 应用场景 渗透测试需要访问某些国内网站(比如edu的),想要隐藏自己,但是国外代理不能访问,也没有稳定的可用代理的时候。 之后,可能我会增加国外代理,实现白嫖科学上网。

urdr-gungnir 45 Nov 17, 2022
An opensource library to use SNMP get/bulk/set/walk in Python

SNMP-UTILS An opensource library to use SNMP get/bulk/set/walk in Python Features Work with OIDS json list [Find Here](#OIDS List) GET command SET com

Alexandre Gossard 3 Aug 03, 2022
批量检查目标是否为cdn

🐸 Frog For Automatic Scan 🐶 Doge For Defense Evasion&Offensive Security Frog-checkCDN 批量检查目标是否为cdn Usage: python3 checkCDN.py list.txt list内可以为ip或者d

TimWhite 119 Dec 27, 2022
High capacity, high availability, well connected, fast lightning node.

LND ⚡ Routing High capacity, high availability, well connected, fast lightning node. We aim to become a top liquidity provider for the lightning netwo

18 Dec 16, 2022
Visualize the electric field of a point charge network.

ElectriPy ⚡ Visualize the electric field of a point charges network. 🔌 Installation Install ElectriPy package: $ pip install electripy You are all d

Dylan Tintenfich 29 Aug 29, 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
Building a Robust IOT device which is customizable, encrypted, secure and user friendly

Building a Robust IOT device which is customizable, encrypted, secure and user friendly, which uses a single GPIO pin to extract multiple sensor values

1 Jan 03, 2022
A TCP Chatroom built with python and TCP/IP sockets, consisting of a server and multiple clients which can connect with the server and chat with each other.

A TCP Chatroom built with python and TCP/IP sockets, consisting of a server and multiple clients which can connect with the server and chat with each other. It also provides an Admin role with featur

3 May 22, 2022
Caching for HTTPX

Caching for HTTPX. Note: Early development / alpha, use at your own risk. This package adds caching functionality to HTTPX Adapted from Eric Larson's

Mehul Solanki 0 Oct 08, 2022
A repository dedicated to IoT(internet of things ) and python scripts

📑 Introduction Week of Learning is a weekly program in which you will get all the necessary knowledge about Circuit-Building, Arduino and Micro-Contr

27 Nov 22, 2022
This program ingests a Cisco "sh ip arp" as a text file and produces the list of vendors seen in the file

IP-ARP-Vendor_lookup This program ingests a Cisco "sh ip arp" as a text file and produces the list of vendors seen in the file Why? Answers the questi

Stew Alexander 1 Dec 24, 2022
A simple, personal chat program that runs on a single computer. No Internet, just you.

MultiChat A simple, personal chat program that runs on a single computer. No Internet, just you. Simple and Local MultiChat was created with ease of u

Owls 2 Aug 19, 2022
Simple local RPG turn-based to play while learn something using the anki system

Simple local RPG turn-based to play while learn something using the anki system

Raphael Kieling 5 Aug 02, 2022
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 05, 2023
CloudProxy is to hide your scrapers IP behind the cloud

Hide your scrapers IP behind the cloud. Provision proxy servers across different cloud providers to improve your scraping success.

Christian Laffin 1.1k Jan 02, 2023
A library for interacting with APNs and VoIP using HTTP/2.

kalyke A library for interacting with APNs and VoIP using HTTP/2. Installation kalyke requires python 3.6 or later. $ pip install kalyke-apns Usage AP

Yuya Oka 11 Dec 08, 2022
IP Rover - An Excellent OSINT tool to get information of any ip address

IP Rover - An Excellent OSINT tool to get information of any ip address. All details are explained in below screenshot

Saad 20 Dec 16, 2022
A simple tool to utilize the basic functionality of the Private API From Virus Total

Welcome To VT-SCAN (viurs total api) Information This is a simple tool to utilize the basic functionality of the Private API From Virus Total. with th

0X0ŽĒR∅⁰ 1 Sep 21, 2022