{"id":28199,"library":"sonora","title":"Sonora","description":"A WSGI and ASGI compatible gRPC-web implementation. Version 0.2.3 supports Python >=3.7,<4.0. Provides middleware for integrating gRPC-web clients with Python web frameworks like Flask (WSGI) or Starlette (ASGI).","status":"active","version":"0.2.3","language":"python","source_language":"en","source_url":"https://github.com/public/sonora","tags":["grpc-web","wsgi","asgi","flask","starlette","grpc"],"install":[{"cmd":"pip install sonora","lang":"bash","label":"Install Sonora"}],"dependencies":[],"imports":[{"note":"SonoraWSGIMiddleware is in the wsgi submodule, not top-level.","wrong":"from sonora import SonoraWSGIMiddleware","symbol":"SonoraWSGIMiddleware","correct":"from sonora.wsgi import SonoraWSGIMiddleware"},{"note":"Correct import for ASGI middleware.","symbol":"SonoraASGIMiddleware","correct":"from sonora.asgi import SonoraASGIMiddleware"},{"note":"client is a module, not a subpackage; import the module directly.","wrong":"import sonora.client","symbol":"sonora.client","correct":"from sonora import client"}],"quickstart":{"code":"from flask import Flask\nfrom sonora.wsgi import SonoraWSGIMiddleware\n\napp = Flask(__name__)\n\n# Placeholder gRPC handler (replace with actual implementation)\ndef my_grpc_handler(request):\n    return {}\n\nsonora_app = SonoraWSGIMiddleware(app, handler=my_grpc_handler)\n\nif __name__ == '__main__':\n    from wsgiref.simple_server import make_server\n    server = make_server('localhost', 5000, sonora_app)\n    server.serve_forever()","lang":"python","description":"Basic WSGI integration with Flask."},"warnings":[{"fix":"Implement a callable handler that matches the gRPC service definition.","message":"Sonora requires an actual gRPC handler; it does not auto-generate stubs. You must define a handler that processes gRPC-web requests.","severity":"gotcha","affected_versions":"all"},{"fix":"Use other libraries like grpcio-web or grpc-gateway for streaming.","message":"Sonora does not support streaming gRPC (both client and server streaming). Only unary calls are supported.","severity":"gotcha","affected_versions":"<=0.2.3"},{"fix":"Monitor the repository for updates or consider alternatives like grpclib or grpc-web.","message":"Sonora's API may change in future versions; the project is experimental and not widely maintained.","severity":"deprecated","affected_versions":"all"},{"fix":"Ensure the handler returns a dict with status, headers, and body.","message":"When using ASGI, SonoraASGIMiddleware expects a handler that returns an HTTP response; it does not integrate with Starlette's request/response cycle directly.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Use: from sonora.wsgi import SonoraWSGIMiddleware","cause":"Attempting to import from the top-level package instead of the wsgi submodule.","error":"ImportError: cannot import name 'SonoraWSGIMiddleware' from 'sonora'"},{"fix":"Define the handler with at least one argument, e.g., def my_handler(request):","cause":"Your handler function does not accept the request argument expected by Sonora.","error":"TypeError: handler() missing 1 required positional argument: 'request'"},{"fix":"Use: from sonora import client","cause":"Importing 'import sonora.client' incorrectly; 'client' is a module, not a subpackage.","error":"AttributeError: module 'sonora' has no attribute 'client'"},{"fix":"Ensure the gRPC-web request path follows the format '/package.Service/Method'. Check the handler implementation.","cause":"The gRPC service name and method are not recognized; likely the request path does not match the expected pattern.","error":"sonora.exceptions.GRPCError: 404 Not Found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}