Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit a5878c4

Browse files
committed
Add documentation
1 parent 12b856b commit a5878c4

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

docs/getting-started.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ You can also use it from `grpcio-tools`:
1010
pip install grpcio-tools
1111
```
1212

13-
1413
## Install `betterproto2_compiler`
1514

1615
It is possible to install `betterproto2_compiler` using pip:
@@ -19,10 +18,6 @@ It is possible to install `betterproto2_compiler` using pip:
1918
pip install betterproto2_compiler
2019
```
2120

22-
!!! warning
23-
The compiler needs Python 3.10, 3.11 or 3.12. Don't worry! The generated code will be compatible with all Python versions from Python 3.8 to Python 3.13.
24-
25-
2621
## Compile a proto file
2722

2823
Create the following `example.proto` file.
@@ -35,6 +30,10 @@ package helloworld;
3530
message HelloWorld {
3631
string message = 1;
3732
}
33+
34+
service HelloService {
35+
rpc SayHello (HelloWorld) returns (HelloWorld);
36+
}
3837
```
3938

4039
You should now be able to compile it using:
@@ -50,3 +49,40 @@ If you installed `protoc` with `grpc-tools`, the command will be:
5049
mkdir lib
5150
python -m grpc.tools.protoc -I . --python_betterproto2_out=lib example.proto
5251
```
52+
53+
### Service compilation
54+
55+
#### Clients
56+
57+
By default, for each service, betterproto will generate a synchronous client. Both synchronous and asynchronous clients
58+
are supported.
59+
60+
- Synchronous clients rely on the `grpcio` package. Make sure to enable the `grpcio` extra package when installing
61+
betterproto2 to use them.
62+
- Asynchronous clients rely on the `grpclib` package. Make sure to enable the `grpclib` extra package when installing
63+
betterproto2 to use them.
64+
65+
To choose which clients to generate, use the `client_generation` option of betterproto. It supports the following
66+
values:
67+
68+
- `none`: Clients are not generated.
69+
- `sync`: Only synchronous clients are generated.
70+
- `async`: Only asynchronous clients are generated.
71+
- `sync_async`: Both synchronous and asynchronous clients are generated.
72+
Asynchronous clients are generated with the Async suffix.
73+
- `async_sync`: Both synchronous and asynchronous clients are generated.
74+
Synchronous clients are generated with the Sync suffix.
75+
- `sync_async_no_default`: Both synchronous and asynchronous clients are generated.
76+
Synchronous clients are generated with the Sync suffix, and asynchronous clients are generated with the Async
77+
suffix.
78+
79+
For example, `protoc -I . --python_betterproto2_out=lib example.proto --python_betterproto2_opt=client_generation=async`
80+
will only generate asynchronous clients.
81+
82+
#### Servers
83+
84+
By default, betterproto will not generate server base classes. To enable them, set the `server_generation` option to
85+
`async` with `--python_betterproto2_opt=server_generation=async`.
86+
87+
These base classes will be asynchronous and rely on `grpclib`. To use them, make sure to install `betterproto2` with the
88+
`grpclib` extra package.

0 commit comments

Comments
 (0)