🌺 Petal - Flask, for gRPC services.
Petal reduces the boilerplate required to write and maintain gRPC based services whilst ensuring your service code is always in sync with your definitions. It aims to be a somewhat opinionated gRPC framework. This is very, very early code.
Installation and features
pip install petal
Right now:
- Define your service methods as simple Python functions
- Ensure they are up to date with service definitions by utilizing type annotations
- Build your proto definitions and run your app with a
petalcommand - Share compiled protobuf definitions as Python packages.
- Streaming requests and responses
Future features:
- Autoreloading during development
- Structured logging
- Some form of plugin architecture
- Distributed tracing
- A testing client
- AsyncIO support
Hello world example:
from petal import Service
from example.protobuf.greeter_pb2 import HelloReply, HelloRequest
service = Service(__name__)
@service.grpc()
def say_hello(request: HelloRequest) -> HelloReply:
return HelloReply(message=f'Hello {request.name}')
Tutorial: Creating a petal app
Lets create a Hello World Petal app. First lets define an entirely useless service. Place the file below
in hello_world/protobuf/service.proto:
syntax = "proto3";
package hello_world.protobuf.service;
service HelloWorld {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
}
message HelloReply {
}
Then run petal build hello_world.
Next, write our service definitions. Create a
hello_world/__init__.py file and add some imports:
from petal import Service
from hello_world.protobuf.service_pb2 import HelloReply, HelloRequest
service = Service(__name__)
This imports the request and response types our service will need. Next we need to fill in the
SayHello method:
@service.grpc()
def say_hello(request: HelloRequest) -> HelloReply:
return HelloReply()
And finally, run the service by executing petal run hello_world.
Now if we modify the service by adding a new method:
message HelloAgain {}
service HelloWorld {
rpc SayHelloAgain (HelloRequest) returns (HelloAgain) {}
}
And run petal build hello_world && petal run hello_world, we get an error:
$ petal run hello_world
Error: Cannot find a suitable method for GRPC method SayHelloAgain
Please ensure one exists in your service code, or use service.grpc(name=NAME) to define one.
Petal is ensuring we have the correct Python methods defined for all our service functions. We can fix this by defining one:
from hello_world.protobuf.service_pb2 import HelloAgain
@service.grpc()
def say_hello_again(request: HelloRequest) -> HelloAgain:
return HelloAgain()
Now running petal serve hello_world will work.
Metadata
Release files for petal 0.0.2.post2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| petal-0.0.2.post2.tar.gz | 7.1 kB | Without provenance | Details for petal-0.0.2.post2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| petal-0.0.2.post2-py3-none-any.whl | Python 3 | none | any | Details for petal-0.0.2.post2-py3-none-any.whl |
Total release size: 15.9 kB
Release files / petal-0.0.2.post2.tar.gz
| Download URL | petal-0.0.2.post2.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94004689fb3d3e3cbbc3d0d4680459232446c47a028f123e4221a632eeb908f0
|
|
BLAKE2b-256 checksum How to use checksums |
5d6495480d3dee916991d0344d0c82d061599cf1cf644eefcbb5126770d7f194
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Release files / petal-0.0.2.post2-py3-none-any.whl
| Download URL | petal-0.0.2.post2-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a25b2401d2f0f8ddab943938966f7cf8378fa3962b3ee2e9ea592c8a1f544f4
|
|
BLAKE2b-256 checksum How to use checksums |
f1bb02a0a6ddcb895eb4b51b5e8d1f4d174d41fe8b652e7e3899d348ac4e0dfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Security for petal 0.0.2.post2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.