Skip to content

Commit 71458b2

Browse files
committed
Move documentation
1 parent 37c56e9 commit 71458b2

5 files changed

Lines changed: 107 additions & 118 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Development
22

3+
This page targets the betterproto maintainers.
4+
35
## Recompiling the lib proto files
46

57
After some updates in the compiler, it might be useful to recompile the standard Google proto files used by the

betterproto2/docs/getting-started.md

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,111 @@
11
Getting Started
22
===============
33

4-
## Installation
4+
## Compilation
5+
6+
7+
### Install protoc
58

6-
The package `betterproto2` can be simply installed from PyPI using `pip`:
9+
The betterproto2 compiler is a plugin of `protoc`, you first need to [install](https://grpc.io/docs/protoc-installation/) it.
10+
11+
You can also use it from `grpcio-tools`:
712

813
```sh
9-
pip install betterproto2[all]
14+
pip install grpcio-tools
15+
```
16+
17+
### Install `betterproto2_compiler`
18+
19+
It is possible to install `betterproto2_compiler` using pip:
20+
21+
```
22+
pip install betterproto2_compiler
23+
```
24+
25+
### Compile a proto file
26+
27+
Create the following `example.proto` file.
28+
29+
```proto
30+
syntax = "proto3";
31+
32+
package helloworld;
33+
34+
message HelloWorld {
35+
string message = 1;
36+
}
37+
38+
service HelloService {
39+
rpc SayHello (HelloWorld) returns (HelloWorld);
40+
}
41+
```
42+
43+
You should be able to compile it using:
44+
45+
```
46+
mkdir lib
47+
protoc -I . --python_betterproto2_out=lib example.proto
48+
```
49+
50+
If you installed `protoc` with `grpc-tools`, the command will be:
51+
1052
```
53+
mkdir lib
54+
python -m grpc.tools.protoc -I . --python_betterproto2_out=lib example.proto
55+
```
56+
57+
#### Service compilation
58+
59+
##### Clients
60+
61+
By default, for each service, betterproto will generate a synchronous client. Both synchronous and asynchronous clients
62+
are supported.
63+
64+
- Synchronous clients rely on the `grpcio` package. Make sure to enable the `grpcio` extra package when installing
65+
betterproto2 to use them.
66+
- Asynchronous clients rely on the `grpclib` package. Make sure to enable the `grpclib` extra package when installing
67+
betterproto2 to use them.
1168

12-
!!! info
13-
The package is compatible with all Python versions from 3.10 to 3.13.
69+
To choose which clients to generate, use the `client_generation` option of betterproto. It supports the following
70+
values:
1471

72+
- `none`: Clients are not generated.
73+
- `sync`: Only synchronous clients are generated.
74+
- `async`: Only asynchronous clients are generated.
75+
- `sync_async`: Both synchronous and asynchronous clients are generated.
76+
Asynchronous clients are generated with the Async suffix.
77+
- `async_sync`: Both synchronous and asynchronous clients are generated.
78+
Synchronous clients are generated with the Sync suffix.
79+
- `sync_async_no_default`: Both synchronous and asynchronous clients are generated.
80+
Synchronous clients are generated with the Sync suffix, and asynchronous clients are generated with the Async
81+
suffix.
1582

16-
## Compiling proto files
83+
For example, `protoc -I . --python_betterproto2_out=lib example.proto --python_betterproto2_opt=client_generation=async`
84+
will only generate asynchronous clients.
1785

18-
Follow the documentation of [betterproto2 compiler](https://betterproto.github.io/python-betterproto2-compiler/getting-started/) to compile your proto files.
86+
##### Servers
87+
88+
By default, betterproto will not generate server base classes. To enable them, set the `server_generation` option to
89+
`async` with `--python_betterproto2_opt=server_generation=async`.
90+
91+
These base classes will be asynchronous and rely on `grpclib`. To use them, make sure to install `betterproto2` with the
92+
`grpclib` extra package.
93+
94+
95+
## Installation
96+
97+
The package `betterproto2` can be installed from PyPI using `pip`:
98+
99+
```sh
100+
pip install betterproto2[all]
101+
```
19102

20103
!!! warning
21104
Make sure that the proto files were generated with a version of `betterproto2_compiler` that is compatible with your
22105
version of `betterproto2`.
23106

24107
The version `0.x.y` of `betterproto` is compatible with the version `0.a.b` of the compiler if and only if `a=b`.
25108

26-
27109
## Basic usage
28110

29111
If you successfuly compiled the `example.proto` file from the compiler documentation, you should now be able to use it!

betterproto2/mkdocs.yml

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
site_name: Betterproto2
2-
site_url: https://betterproto.github.io/python-betterproto2/
2+
site_url: https://betterproto.github.io/
33
theme:
44
name: material
55
palette:
66
primary: deep orange
77
accent: deep orange
8-
9-
features:
10-
- navigation.tabs
118

129
nav:
13-
- Betterproto2:
14-
- index.md
15-
- Getting Started: getting-started.md
16-
- Tutorial:
17-
- Messages: tutorial/messages.md
18-
- Clients: tutorial/clients.md
19-
- API: api.md
20-
- Betterproto2 compiler: https://betterproto.github.io/python-betterproto2-compiler/
10+
- index.md
11+
- Getting Started: getting-started.md
12+
- Tutorial:
13+
- Messages: tutorial/messages.md
14+
- Clients: tutorial/clients.md
15+
- API: api.md
16+
- Development: development.md
17+
2118

2219
plugins:
23-
- search
24-
- mkdocstrings:
25-
handlers:
26-
python:
27-
options:
28-
show_source: false
20+
- search
21+
- mkdocstrings:
22+
handlers:
23+
python:
24+
options:
25+
show_source: false
2926

3027
markdown_extensions:
3128
- admonition

betterproto2_compiler/docs/getting-started.md

Lines changed: 0 additions & 88 deletions
This file was deleted.

betterproto2_compiler/docs/index.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)