METADATA 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. Metadata-Version: 2.4
  2. Name: connectrpc
  3. Version: 0.11.1
  4. Summary: Server and client runtime library for Connect RPC
  5. Keywords: connect,grpc,http,protobuf,rpc
  6. License-Expression: Apache-2.0
  7. License-File: LICENSE
  8. Classifier: Development Status :: 4 - Beta
  9. Classifier: Intended Audience :: Developers
  10. Classifier: Operating System :: OS Independent
  11. Classifier: Programming Language :: Python :: 3
  12. Classifier: Programming Language :: Python :: 3 :: Only
  13. Classifier: Programming Language :: Python :: 3.10
  14. Classifier: Programming Language :: Python :: 3.11
  15. Classifier: Programming Language :: Python :: 3.12
  16. Classifier: Programming Language :: Python :: 3.13
  17. Classifier: Programming Language :: Python :: 3.14
  18. Classifier: Topic :: Internet :: WWW/HTTP
  19. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  20. Classifier: Typing :: Typed
  21. Requires-Dist: protobuf-py==0.1.1
  22. Requires-Dist: pyqwest>=0.5.1
  23. Maintainer: Anuraag Agrawal, Spencer Nelson, Stefan VanBuren, Yasushi Itoh
  24. Maintainer-email: Anuraag Agrawal <anuraaga@gmail.com>, Spencer Nelson <spencer@firetiger.com>, Stefan VanBuren <stefan@vanburen.xyz>, Yasushi Itoh <i2y.may.roku@gmail.com>
  25. Requires-Python: >=3.10
  26. Project-URL: Documentation, https://connectrpc.com/docs/python/getting-started/
  27. Project-URL: Homepage, https://github.com/connectrpc/connect-py
  28. Project-URL: Issues, https://github.com/connectrpc/connect-py/issues
  29. Project-URL: Repository, https://github.com/connectrpc/connect-py
  30. Description-Content-Type: text/markdown
  31. <div align="center">
  32. ![The Connect logo](https://raw.githubusercontent.com/connectrpc/connectrpc.com/12f7ad8e95c5f784700bc280708b27cd148d0cf1/public/img/logos/simple-connect.svg)
  33. # Connect for Python
  34. [![PyPI version](https://img.shields.io/pypi/v/connectrpc?style=flat-square)](https://pypi.org/project/connectrpc)
  35. [![License](https://img.shields.io/pypi/l/connectrpc?style=flat-square)](https://github.com/connectrpc/connect-py/blob/main/LICENSE)
  36. [![Slack](https://img.shields.io/badge/slack-buf-%23e01e5a?style=flat-square)](https://buf.build/links/slack)
  37. Connect is the **easiest way to build modern APIs**.
  38. [Docs](https://connectrpc.com/docs/python/getting-started/) •
  39. [Example](https://github.com/connectrpc/connect-py/tree/main/example) •
  40. [New to Connect?](https://connectrpc.com/)
  41. </div>
  42. ## Why Connect?
  43. Building an API usually means writing the same types at least twice: once on the server, and once in every client. Connect makes this simple - define your API schema using Protobuf, and Connect generates type-safe server stubs and idiomatic client libraries in **every major language**, including for your frontend. All that's left to write is your business logic, in plain Python.
  44. Connect already works with your current tech stack:
  45. - Connect is built on top of HTTP and speaks both Protobuf and JSON, so `curl` works out of the box.
  46. - It interoperates seamlessly with gRPC and gRPC-Web, and supports streaming as a first-class feature.
  47. - It runs on WSGI/ASGI. Build Connect APIs *alongside* your current API framework - all in the same app.
  48. ## Features
  49. - **Servers:** WSGI and ASGI-ready, use with any [compatible server](https://connectrpc.com/docs/python/deployment/)
  50. - **Clients:** Lightweight sync and async clients, backed by `pyqwest`
  51. - **Protocols:** Supports Connect, gRPC, and gRPC-Web (HTTP/1.1 and HTTP/2)
  52. - **Type safety:** Fully type-annotated generated code
  53. - **Streaming:** Full support for server, client, and bidirectional streaming
  54. - **Compression:** Built-in support for gzip, brotli, and zstd
  55. - **Middleware:** Server- and client-side interceptors for telemetry, logging, etc.
  56. - **Compliant:** Verified using the official [Connect conformance](https://github.com/connectrpc/conformance) test suite
  57. ## Getting started
  58. Install the runtime library:
  59. ```bash
  60. uv add connectrpc
  61. ```
  62. For codegen, install [`buf`](https://github.com/bufbuild/buf) and create `buf.gen.yaml`:
  63. ```yaml
  64. version: v2
  65. plugins:
  66. - remote: buf.build/bufbuild/py
  67. out: gen
  68. - remote: buf.build/connectrpc/py
  69. out: gen
  70. ```
  71. <details>
  72. <summary><b>Local plugin setup</b></summary>
  73. The example above uses a Buf-hosted plugin server. To generate code entirely locally, install the relevant plugins:
  74. ```bash
  75. uv add --dev protoc-gen-py protoc-gen-connectrpc
  76. ```
  77. Now edit your `buf.gen.yaml`:
  78. ```yaml
  79. version: v2
  80. plugins:
  81. - local: .venv/bin/protoc-gen-py
  82. out: gen
  83. - local: .venv/bin/protoc-gen-connectrpc
  84. out: gen
  85. ```
  86. </details>
  87. <details>
  88. <summary><b>Compatibility with <code>google-protobuf</code></b></summary>
  89. Connect defaults to targeting [protobuf-py](https://protobufpy.com) as the Protocol Buffers implementation, but it also supports Google's Protocol Buffers for Python. Pass `protobuf=google` to the codegen plugin to use it.
  90. ```yaml
  91. version: v2
  92. plugins:
  93. - remote: buf.build/protocolbuffers/python
  94. out: .
  95. - remote: buf.build/protocolbuffers/pyi
  96. out: .
  97. - remote: buf.build/connectrpc/py
  98. out: .
  99. opt: protobuf=google
  100. ```
  101. If configuring a client for JSON codec, make sure to pass `connectrpc.compat.google_protobuf_json_codec` instead of `connectrpc.codec.proto_json_codec`.
  102. </details>
  103. ## Usage
  104. A basic Connect server is easy to set up. Just import the stubs, subclass the generated service, and serve:
  105. ```python
  106. from connectrpc.request import RequestContext
  107. from your_service_pb import HelloRequest, HelloResponse
  108. from your_service_connect import HelloService, HelloServiceASGIApplication
  109. class MyHelloService(HelloService):
  110. async def say_hello(self, request: HelloRequest, ctx: RequestContext) -> HelloResponse:
  111. return HelloResponse(message=f"Hello, {request.name}!")
  112. # Create ASGI app
  113. app = HelloServiceASGIApplication(MyHelloService())
  114. # Run with any ASGI server, e.g. uvicorn:
  115. # uvicorn server:app --port 8080
  116. ```
  117. Client libraries are automatically generated for you. Here's what the async client looks like:
  118. ```python
  119. from your_service_pb import HelloRequest, HelloResponse
  120. from your_service_connect import HelloServiceClient
  121. async def main():
  122. # Create async client
  123. async with HelloServiceClient("https://api.example.com") as client:
  124. response = await client.say_hello(HelloRequest(name="World"))
  125. print(response.message) # "Hello, World!"
  126. ```
  127. And the sync client:
  128. ```python
  129. from your_service_pb import HelloRequest
  130. from your_service_connect import HelloServiceClientSync
  131. def main():
  132. # Create sync client
  133. with HelloServiceClientSync("https://api.example.com") as client:
  134. response = client.say_hello(HelloRequest(name="World"))
  135. print(response.message) # "Hello, World!"
  136. if __name__ == "__main__":
  137. main()
  138. ```
  139. Check out [the docs](https://connectrpc.com/docs/python/getting-started/) for more detailed usage.
  140. - [**Streaming:**](https://connectrpc.com/docs/python/streaming/) Connect supports server-side, client-side, and bidirectional streaming.
  141. - [**Interceptors:**](https://connectrpc.com/docs/python/interceptors/) Set up middleware for logging, observability, and metrics.
  142. - [**Other languages:**](https://connectrpc.com/docs/introduction/) Generate clients for use in other languages.