Skip to content

Commit cd2be57

Browse files
Improve the documentation (#49)
1 parent 69d77be commit cd2be57

File tree

3 files changed

+24
-77
lines changed

3 files changed

+24
-77
lines changed

docs/quick-start.md renamed to docs/getting-started.md

Lines changed: 19 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,44 @@ Getting Started
33

44
## Installation
55

6-
Installation from PyPI is as simple as running:
6+
The package `betterproto2` can be simply installed from PyPI using `pip`:
77

88
```sh
9-
python3 -m pip install -U betterproto
9+
pip install betterproto2
1010
```
1111

12-
If you are using Windows, then the following should be used instead:
12+
!!! info
13+
The package is compatible with all Python versions from 3.8 to 3.13.
1314

14-
```sh
15-
py -3 -m pip install -U betterproto
16-
```
1715

18-
To include the protoc plugin, install `betterproto[compiler]` instead of betterproto,
19-
e.g.
16+
## Compiling proto files
2017

21-
```sh
22-
python3 -m pip install -U "betterproto[compiler]"
23-
```
18+
Follow the documentation of [betterproto2 compiler](https://betterproto.github.io/python-betterproto2-compiler/getting-started/) to compile your proto files.
2419

2520
!!! warning
2621
Make sure that the proto files were generated with a version of `betterproto2_compiler` that is compatible with your
2722
version of `betterproto2`.
2823

29-
The version `x.y.z` of `betterproto` is compatible with the version `a.b.c` of the compiler if and only if `a=x` and
30-
`b=y`.
31-
32-
## Compiling proto files
33-
34-
35-
Given you installed the compiler and have a proto file, e.g `example.proto`:
24+
The version `0.x.y` of `betterproto` is compatible with the version `0.a.b` of the compiler if and only if `a=b`.
3625

37-
```proto
38-
syntax = "proto3";
39-
40-
package hello;
4126

42-
// Greeting represents a message you can tell a user.
43-
message Greeting {
44-
string message = 1;
45-
}
46-
```
27+
## Basic usage
4728

48-
To compile the proto you would run the following:
49-
50-
You can run the following to invoke protoc directly:
51-
52-
```sh
53-
mkdir hello
54-
protoc -I . --python_betterproto_out=lib example.proto
55-
```
56-
57-
or run the following to invoke protoc via grpcio-tools:
58-
59-
```sh
60-
pip install grpcio-tools
61-
python -m grpc_tools.protoc -I . --python_betterproto_out=lib example.proto
62-
```
63-
64-
65-
This will generate `lib/__init__.py` which looks like:
29+
If you successfuly compiled the `example.proto` file from the compiler documentation, you should now be able to use it!
6630

6731
```python
68-
# Generated by the protocol buffer compiler. DO NOT EDIT!
69-
# sources: example.proto
70-
# plugin: python-betterproto
71-
from dataclasses import dataclass
72-
73-
import betterproto
74-
75-
76-
@dataclass
77-
class Greeting(betterproto.Message):
78-
"""Greeting represents a message you can tell a user."""
79-
80-
message: str = betterproto.string_field(1)
32+
>>> from lib.helloworld import HelloWorld
33+
>>> msg = HelloWorld(message="Hello world!")
34+
>>> msg
35+
HelloWorld(message='Hello world!')
36+
>>> bytes(msg)
37+
b'\n\x0cHello world!'
38+
>>> msg.to_dict()
39+
{'message': 'Hello world!'}
8140
```
8241

83-
Then to use it:
84-
85-
```python
86-
>>> from lib import Greeting
87-
88-
>>> test = Greeting()
89-
>>> test
90-
Greeting(message='')
91-
92-
>>> test.message = "Hey!"
93-
>>> test
94-
Greeting(message="Hey!")
95-
96-
>>> bytes(test)
97-
b'\n\x04Hey!'
98-
>>> Greeting().parse(serialized)
99-
Greeting(message="Hey!")
100-
```
42+
!!! Warning
43+
The rest of the documentation is not up to date.
10144

10245

10346
## Async gRPC Support

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ theme:
1212
nav:
1313
- Betterproto2:
1414
- index.md
15-
- Quick start: quick-start.md
15+
- Getting Started: getting-started.md
1616
- Tutorial:
1717
- Messages: tutorial/messages.md
1818
- API: api.md

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ rm -rf compiled_files
135135
"""
136136
help = "Pulls the compiled test files from the betterproto2-compiler repository"
137137

138+
[tool.poe.tasks.serve-docs]
139+
cmd = "mkdocs serve"
140+
help = "Serve the documentation locally"
141+
138142
# CI tasks
139143

140144
[tool.poe.tasks.full-test]

0 commit comments

Comments
 (0)