Skip to content

Commit 1c7eea3

Browse files
authored
Add doc on deployment (#52)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
1 parent 33ea0d6 commit 1c7eea3

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

docs/deployment.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Deployment
2+
3+
After building a Connect service, you still need to deploy it to production. This guide covers how to
4+
use a Python application server to run a service.
5+
6+
## Application Servers
7+
8+
Connect services are standard ASGI or WSGI applications that can be run with an off-the-shelf Python
9+
application server. Generally, any experience in running a Python application can be applied to running
10+
Connect as-is.
11+
12+
### HTTP/1.1
13+
14+
Connect only requires HTTP/2 for bidirectional streaming RPCs - the vast majority of services can be run
15+
using HTTP/1.1 without issue. Two servers have long been in use with HTTP/1.1 and have a proven track
16+
record. If you are unsure what server to use, it is generally a safe bet to use one of them:
17+
18+
- [gunicorn](http://www.gunicorn.org/) for WSGI applications
19+
- [uvicorn](https://uvicorn.dev/) for ASGI applications
20+
21+
### HTTP/2
22+
23+
If your service uses bidirectional or otherwise want to use HTTP/2, the above servers will not work.
24+
HTTP/2 support in the Python ecosystem is still relatively young - servers known to support HTTP/2
25+
with bidirectional streaming are:
26+
27+
- [granian](https://github.com/emmett-framework/granian)
28+
- [hypercorn](https://hypercorn.readthedocs.io/en/latest/)
29+
- [pyvoy](https://github.com/curioswitch/pyvoy)
30+
31+
Connect has an extensive test suite to verify compatibility of connect-python with the Connect protocol.
32+
Unfortunately, we are only able to reliably pass the suite with pyvoy, with other servers occasionally
33+
having hung requests or stream ordering issues. pyvoy was built with connect-python in mind but is
34+
very new and needs more time with real-world applications to verify stability.
35+
36+
Keep the above in mind when picking an HTTP/2 server and let us know how it goes if you give any a try.
37+
When in doubt, if you do not use bidirectional streaming, we recommend one of the HTTP/1.1 servers.
38+
39+
## CORS
40+
41+
Connect services are standard ASGI and WSGI applications so any CORS middleware can be used to
42+
enable it.
43+
44+
For example, with an ASGI application using the [asgi-cors](https://pypi.org/project/asgi-cors/)
45+
middleware:
46+
47+
```python
48+
from asgi_cors import asgi_cors
49+
50+
from greet.v1.greet_connect import GreetServiceASGIApplication
51+
from server import Greeter
52+
53+
app = GreetServiceASGIApplication(Greeter())
54+
55+
# app is a standard ASGI application - any middleware works as-is
56+
app = asgi_cors(
57+
app,
58+
hosts=["https://acme.com"],
59+
# POST is used for all APIs except for idempotent unary RPCs that may support GET
60+
methods=["GET", "POST"],
61+
headers=[
62+
"content-type",
63+
"connect-protocol-version",
64+
"connect-timeout-ms",
65+
"x-user-agent",
66+
],
67+
)
68+
```

0 commit comments

Comments
 (0)