Python dataclasses for the Envoy Data-Plane-API
Project description
envoy_data_plane
A conversion of envoyproxy/data-plane-api protocol buffers into Python dataclasses using betterproto
Intended usage
This is a helper library that allows importing every type available in the envoy API.
One use-case might be generating Envoy configuration using a Python script.
In my case, I will use this library in my custom built control-plane, so that I have autocompletion in my IDE, and a basic form of validation.
In future, this may also help with building an idiomatic GRPC control-plane in Python.
Installation
This package is published to PyPI:
python -m pip install envoy_data_plane
Example
import stringcase
import json
import envoy_data_plane.envoy.api.v2 as envoy
route_config = envoy.RouteConfiguration(
name='MyRouteConfig',
virtual_hosts=[
envoy.route.VirtualHost(
name='SomeWebsite',
domains=['foobar.com'],
routes=[
envoy.route.Route(
name='catchall',
match=envoy.route.RouteMatch(
prefix='/'
),
direct_response=envoy.route.DirectResponseAction(
status=200,
body=envoy.core.DataSource(
inline_string='Hello there'
)
)
)
]
)
]
)
response = envoy.DiscoveryResponse(
version_info='0',
resources=[
route_config
],
)
print(
json.dumps(response.to_dict(casing=stringcase.snakecase), indent=2)
)
Result:
{
"version_info": "0",
"resources": [
{
"name": "MyRouteConfig",
"virtual_hosts": [
{
"name": "SomeWebsite",
"domains": [
"foobar.com"
],
"routes": [
{
"name": "catchall",
"match": {
"prefix": "/",
"headers": [],
"query_parameters": []
},
"direct_response": {
"status": 200,
"body": {
"inline_string": "Hello there"
}
},
"request_headers_to_add": [],
"response_headers_to_add": []
}
],
"virtual_clusters": [],
"rate_limits": [],
"request_headers_to_add": [],
"response_headers_to_add": []
}
],
"response_headers_to_add": [],
"request_headers_to_add": []
}
]
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
envoy_data_plane-0.1.1.tar.gz
(355.8 kB
view hashes)
Built Distributions
Close
Hashes for envoy_data_plane-0.1.1-py3.8.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a890ef5a2a35fdd664cc8e29c9ffb8709f78bd5c55f0e6876037a6afd0c6018 |
|
MD5 | ca21bc04b48ff5161a223fc6fb0bcb2e |
|
BLAKE2b-256 | 134476e3ace45e2178e7c5a895ba32f32e48be4c42c127d9a576f6d7d954e9de |
Close
Hashes for envoy_data_plane-0.1.1-py3.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | abc652a04bdab74d0d9c4445e6dc05ed02207841518f20b99d3c873dbdef7b49 |
|
MD5 | ba227152e48948c286e7b74a21aeb421 |
|
BLAKE2b-256 | e6ff2c57e15d6bba1381be6161ab7e3ea117142f5b99ec0c5ece9f40751e60c1 |