This is a simple AVRO IPC endpoint registration extension for Flask.
For information about AVRO checkout:
* [https://avro.apache.org/](https://avro.apache.org/)
* [http://avro.apache.org/docs/current/spec.html](http://avro.apache.org/docs/current/spec.html)
# Usage
This extension allows you to register a AVRO protocol to a specific URL route. This allows you to handle the messages defined in the protocol.
Given a AVRO protocol `test.avpr`:
```
{
"namespace": "org.avro",
"protocol": "Test",
"types": [
{
"name": "Message",
"type": "record",
"fields": [
{
"name": "from",
"type": "string"
},
{
"name": "body",
"type": "string"
}
]
}
],
"messages": {
"echo_message": {
"request": [
{
"name":"message",
"type":"Message"
}
],
"response": "string",
"errors": []
}
}
}
```
An example of a simple Flask app that implements logic for the message `echo_message`, you could do the following:
```
from flask import Flask
from flask.ext.avro import FlaskAvroEndpoint
test_avro_endpoint = FlaskAvroEndpoint.from_filename("test", "test.avpr")
@test_avro_endpoint.register("echo_message"):
def handle_test_send(request_message):
return request_message.get("body")
app = Flask(__name__)
test_avro_endpoint.connect(app, "/")
```
The above code registers a function that will handle the request message when the endpoint receives a message for `echo_message`. The function is responsible for also returning the correct object that is required as response of the protocol.
In order to interact with endpoint, the client would use the AVRO IPC `Requestor` API for your specific language.
For Python, you'll have to install the `avro` package with pip and then your client could look like this:
```
from avro.protocol import protocol
from avro.ipc import Requestor, HTTPTransceiver
TEST_PROTOCOL = protocol.parse(open("test.avpr").read())
client = HTTPTransceiver("localhost", 9090)
requestor = Requestor(TEST_PROTOCOL, client)
test_message = {
"from": "Ground Control",
"body": "Take your protein pills and put your helmet on"
}
response = requestor.request("echo_message", test_message)
client.close()
```
# Test Helpers
This module also includes a test helper to test your Avro endpoints. Normally, when you test your views, you'll want to use the `test_flask_app.test_client()` to generate requests to your view endpoints. However, creating AVRO request messages is a little cumbersome.
To help facilitate testing, there is a test utility class `flask.ext.avro.util.FlaskAvroTestClient`. This is a convenience wrapper around the test_client.
Example usage:
```
from unittest import TestCase
from flask.ext.avro.util import FlaskAvroTestClient
from avro.protocol import protocol
TEST_PROTOCOL = protocol.parse(open("test.avpr").read())
class TestAvroEndpoint(TestCase):
def setUp(self):
# Generate your test app or pull a created one
...
self.app = test_app
def test_endpoint(self):
client = FlaskAvroTestClient(TEST_PROTOCOL, self.app.test_client(), "/")
test_body = "Take your protein pills and put your helmet on"
test_message = test_message = {
"from": "Ground Control",
"body": test_body
}
response = client.request("echo_message", test_message)
self.assertEqual(test_body, response)
```
-------------------------------------------------------------------------------
0.0.1
-------------------------------------------------------------------------------
- Initial public version.
-------------------------------------------------------------------------------
Metadata
Release files for flask-avro 0.0.1
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 |
|---|---|---|---|---|
| flask-avro-0.0.1.tar.gz | 5.4 kB | Without provenance | Details for flask-avro-0.0.1.tar.gz |
Release files / flask-avro-0.0.1.tar.gz
| Download URL | flask-avro-0.0.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
25db22263639f1c9092a7f96b63a3fee2651160910232f81bc4e531528aacf0c
|
|
BLAKE2b-256 checksum How to use checksums |
d7fe49f85fb3ca382761d53ad5d93a80acaaa794e040d19ff7a02bc346814d78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for flask-avro 0.0.1
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.