Skip to content

Commit edbf82c

Browse files
docs: update README and translate PROTOS.md to English
Signed-off-by: kmilo <kmilo.denis.glez@yandex.com>
1 parent 85666ca commit edbf82c

2 files changed

Lines changed: 105 additions & 35 deletions

File tree

‎PROTOS.md‎

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,65 @@
11
Protobufs / How to handle `fabric-protos`
2-
========================================
2+
=========================================
33

4-
Resumen
4+
Summary
55
-------
66

7-
Hyperledger Fabric define sus interfaces gRPC en `fabric-protos` (Apache-2.0). Para implementar un shim en Python hay dos opciones razonables:
7+
Hyperledger Fabric defines its gRPC interfaces in the `fabric-protos` repository
8+
(Apache-2.0). When implementing a Python shim you generally have two practical
9+
options:
810

9-
1. "Submodular / generar": Mantener `fabric-protos` como submódulo (o referenciar una versión fija), y generar los archivos Python (`*_pb2.py`, `*_pb2_grpc.py`) con `grpc_tools.protoc` usando `scripts/gen_protos.sh`. Opcionalmente, incluir los archivos generados en `src/protos/` para simplificar la instalación de usuarios.
11+
1. "Submodule and generate": Add `fabric-protos` as a submodule (or reference a
12+
fixed tag) and generate Python bindings (`*_pb2.py`, `*_pb2_grpc.py`) using
13+
`grpc_tools.protoc` or `protoc` with a Python plugin. The provided
14+
`scripts/gen_protos.sh` can be used for this. Optionally include the
15+
generated files in the package for releases to simplify consumers' setup.
1016

11-
2. "Empaquetar protos pre-generados": Incluir directamente los archivos Python generados en el paquete (`src/`), y documentar la versión de `fabric-protos` usada. Esto evita que los consumidores instalen `grpc_tools` para usar la librería.
17+
2. "Package pre-generated protos": Commit the generated Python bindings into
18+
the repository/package and document the exact `fabric-protos` version used to
19+
generate them. This avoids requiring consumers to generate bindings locally.
1220

13-
Recomendación (mejor equilibrio al comenzar)
14-
------------------------------------------
21+
Recommendation (practical balance)
22+
----------------------------------
1523

16-
- Use `fabric-protos` como submódulo apuntando a la versión que quiere soportar (por ejemplo `v2.4.0`). Esto preserva el historial y permite reproducibilidad.
17-
- Añada `scripts/gen_protos.sh` (ya existe) para generar bindings. Committee los archivos generados en `src/protos/` solo para releases (o para facilitar pruebas), pero mantenga la fuente `.proto` separada.
18-
- En `pyproject.toml` incluya los archivos generados en el paquete (o genere en la fase de `bdist_wheel`). En CI, genere y valide que los archivos generados son consistentes con el submódulo.
19-
- No publique un paquete PyPI con el nombre `fabric-protos-python` que pueda confundirse con proyectos oficiales; si usted ya tiene un paquete con ese nombre, prefiera un nombre con un prefijo (por ejemplo `fabric_protos_py` o `hyperledger_fabric_protos_py`) y documente claramente la compatibilidad de versión.
24+
- Use `fabric-protos` as a submodule pinned to the exact tag you support. This
25+
preserves provenance and makes regenerating bindings reproducible.
26+
- Keep `scripts/gen_protos.sh` in the repo as a canonical way to regenerate
27+
bindings. Commit generated bindings for release artifacts (or for ease of
28+
testing), but avoid mixing `.proto` sources into the runtime package unless
29+
required.
30+
- In CI, either regenerate the bindings and compare them with the committed
31+
files, or regenerate them as part of the release build to ensure consistency.
32+
- Avoid publishing a PyPI package name that could be confused with an official
33+
upstream package (e.g. `fabric-protos-python`). If publishing generated
34+
bindings, choose a clear, distinct package name and document compatibility.
2035

21-
Pasos prácticos (ejemplo)
36+
Practical steps (example)
2237
-------------------------
2338

24-
1. Añadir `fabric-protos` como submódulo:
39+
1. Add `fabric-protos` as a submodule and pin to a tag:
2540

2641
```bash
27-
git submodule add --depth 1 -b v2.4.0 https://github.com/hyperledger/fabric-protos.git protos/fabric-protos
42+
git submodule add --depth 1 -b v2.5.0 https://github.com/hyperledger/fabric-protos.git protos/fabric-protos
2843
git submodule update --init --recursive
2944
```
3045

31-
2. Generar los protos Python (desde la raíz del repo):
46+
2. Generate Python bindings (run from the repository root):
3247

3348
```bash
3449
cd ./fabric-chaincode-python
35-
./scripts/gen_protos.sh
36-
# los archivos generados irán a src/protos/ por defecto
50+
PROTO_SRC=protos/fabric-protos bash scripts/gen_protos.sh
51+
# generated files will be placed where the script is configured (e.g. fabric_protos_python/)
3752
```
3853

39-
3. Validar en CI que los protos generados son consistentes o regenerarlos en la fase de build.
54+
3. In CI: either regenerate and `git diff` against committed bindings to detect
55+
drift, or regenerate in the build environment so wheel artifacts include the
56+
bindings.
4057

41-
Licencia
42-
--------
58+
License
59+
-------
4360

44-
`fabric-protos` está bajo Apache-2.0. Si incluye `.proto` o archivos generados en su repo, conserve la referencia de licencia (no elimine los archivos LICENSE de `fabric-protos` si los copia). Esto es necesario para poder migrar a Hyperledger Labs sin problemas.
61+
`fabric-protos` is licensed under Apache-2.0. If you include `.proto` files or
62+
generated bindings from that repository in your project, retain the original
63+
license notice (do not remove the `LICENSE` files from the `fabric-protos`
64+
source when copying). This is important if you plan to contribute or migrate the
65+
project to Hyperledger Labs.

‎README.md‎

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,82 @@
11
# fabric-chaincode-python
2-
Hyperledger Fabric Contract and Chaincode implementation for Python https://wiki.hyperledger.org/display/fabric
32

4-
## 🚀 Quick Testing
3+
Hyperledger Fabric Chaincode shim and Contract API for Python.
54

6-
This library has only been tested with python versions 3.8 and 3.9
5+
Status
6+
------
7+
- Experimental implementation of a Python chaincode shim and contract API.
8+
- CI runs with Python 3.11; supported Python versions are 3.10 and 3.11.
9+
10+
Requirements
11+
------------
12+
- Python 3.10+ (3.11 recommended)
13+
- See `requirements.txt` for runtime dependencies. Key packages:
14+
- `grpcio==1.51.3`
15+
- `protobuf>=7.35.1`
16+
- `grpclib==0.4.3`
17+
18+
Quick start (development)
19+
-------------------------
20+
Clone the repository and create a virtual environment:
721

8-
### Install dependencies
9-
Run the following instructions in terminal:
1022
```bash
11-
cd fabric-chaincode-python/
23+
git clone https://github.com/kmilodenisglez/fabric-chaincode-python.git
24+
cd fabric-chaincode-python
25+
python3 -m venv .venv
26+
source .venv/bin/activate
27+
python -m pip install --upgrade pip
28+
pip install -r requirements.txt
1229
```
1330

31+
Run tests:
32+
1433
```bash
15-
python -m pip install fabric-protos-python==2.4 grpcio
34+
pytest -q
1635
```
1736

18-
### Export the environment variables
37+
Build a wheel (release)
38+
-----------------------
39+
Build a wheel that can be published or installed:
1940

20-
Export the chaincode package ID, ex:
2141
```bash
22-
export CHAINCODE_ID=basic_1.0:f3e2ca5115bba71aa2fd16e35722b420cb29c42594f0fdd6814daedbc2130b80
42+
python -m pip install --upgrade build
43+
python -m build --wheel --no-isolation
44+
# artifact will be in dist/*.whl
2345
```
2446

25-
Set the chaincode server address:
47+
Protobuf bindings
48+
-----------------
49+
This repository contains generated Python protobuf bindings for Hyperledger
50+
Fabric under the `fabric_protos_python/` package. The project also includes a
51+
`scripts/gen_protos.sh` helper to regenerate bindings from the `fabric-protos`
52+
source (recommended to use a pinned tag/submodule for reproducible results).
53+
54+
If you regenerate protos in CI or locally, ensure the `protobuf` runtime used
55+
to generate the files is compatible with the installed `protobuf` package
56+
(see `requirements.txt`).
57+
58+
Running a chaincode service (example)
59+
------------------------------------
60+
Set the environment variables expected by the example chaincode server:
61+
2662
```bash
63+
export CHAINCODE_ID=basic_1.0:your_package_id_here
2764
export CHAINCODE_SERVER_ADDRESS=127.0.0.1:9999
2865
```
2966

30-
### Start chaincode service:
67+
Then start the example service (if `main.py` or an example is present):
68+
3169
```bash
32-
python main.py
33-
```
70+
python main.py
71+
```
72+
73+
Contributing
74+
------------
75+
- Follow the Developer Certificate of Origin (DCO): sign commits with
76+
`Signed-off-by: Your Name <you@example.com>` (the repository contains a
77+
DCO check workflow).
78+
- The project uses the Apache-2.0 license.
79+
80+
More information
81+
----------------
82+
See `PROTOS.md` for guidance on handling Fabric protobufs and `scripts/gen_protos.sh` for regeneration instructions.

0 commit comments

Comments
 (0)