Giter VIP home page Giter VIP logo

todo_grpc's Introduction

Todo application using grpc, protobuf, sqlalchemy (alembic)

Create a virtualenv and install dependencies

mkvirtualenv alembic_sample --python=/usr/local/bin/python3
pip install -r requirements.txt

Create a mysql database: todo

Configure migrations/env.py to update the sqlalchemy.url config if the default config is different from your local setup.

Running the migrations

alembic upgrade head

To run grpc server

python todo_server.py

To generate pb2 and pb2_grpc files

python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. todo.proto

Connecting to grpc server from python terminal.

This is how clients connect to grpc and call rpc methods.

import grpc

import todo_pb2, todo_pb2_grpc


MAX_MESSAGE_LENGTH = 4 * 1024 * 1024 * 10
options = [
    ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
    ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH)
]

channel = grpc.insecure_channel(
    'localhost:50051',
    options=options,
)
stub = todo_pb2_grpc.TodoServiceStub(channel)

GetUsers

stub.GetUsers(todo_pb2.UsersRequest())

GetUser

stub.GetUser(todo_pb2.User(id=1))

GetUserTodos

stub.GetUserTodos(todo_pb2.User(id=1))

GetTodo

stub.GetTodo(todo_pb2.Todo(id=3))

CreateUser

user_req = todo_pb2.User(name="abc", email="[email protected]")
user_resp = stub.CreateUser(user_req)

### CreateTodo

todo_grpc's People

Contributors

goutham2027 avatar

Watchers

James Cloos avatar Mahendra Yadav avatar

Forkers

userimack

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.