Skip to content

Commit b4d9d1f

Browse files
authored
Add gRPC interface generation using grpcio-tools (#7)
1 parent ab9bebb commit b4d9d1f

20 files changed

+4484
-34
lines changed

README.md

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,71 @@ cd cadence-python-client
5454
pip install -e ".[dev]"
5555
```
5656

57-
### Generate Protobuf Files
57+
### Generate Protobuf and gRPC Files
5858

5959
Run the generation script:
6060
```bash
61+
# Using uv (recommended)
62+
uv run python scripts/generate_proto.py
63+
64+
# Or using traditional Python
6165
python scripts/generate_proto.py
6266
```
6367

6468
This will:
6569
- Download protoc 29.1 binary
66-
- Generate Python files in `cadence/api/v1/`
67-
- Create proper package structure
70+
- Install grpcio-tools if needed
71+
- Generate Python protobuf files in `cadence/api/v1/`
72+
- Generate gRPC service files in `cadence/api/v1/`
73+
- Create proper package structure with both protobuf and gRPC imports
6874

6975
### Test
7076

7177
Verify the generated files work:
7278
```bash
79+
# Using uv (recommended)
80+
uv run python cadence/sample/simple_usage_example.py
81+
uv run python cadence/sample/grpc_usage_example.py
82+
83+
# Or using traditional Python
7384
python cadence/sample/simple_usage_example.py
85+
python test_grpc_with_examples.py
7486
```
7587

76-
### Usage
88+
### Development Script
89+
90+
The project includes a development script that provides convenient commands for common tasks:
91+
92+
```bash
93+
# Generate protobuf files
94+
uv run python scripts/dev.py protobuf
95+
96+
# Run tests
97+
uv run python scripts/dev.py test
98+
99+
# Run tests with coverage
100+
uv run python scripts/dev.py test-cov
101+
102+
# Run linting
103+
uv run python scripts/dev.py lint
104+
105+
# Format code
106+
uv run python scripts/dev.py format
107+
108+
# Install in development mode
109+
uv run python scripts/dev.py install
110+
111+
# Install with dev dependencies
112+
uv run python scripts/dev.py install-dev
77113

78-
```python
79-
from cadence.api.v1 import workflow, common, domain
114+
# Build package
115+
uv run python scripts/dev.py build
80116

81-
# Create objects
82-
wf_exec = common.WorkflowExecution()
83-
wf_exec.workflow_id = "my-workflow"
117+
# Clean build artifacts
118+
uv run python scripts/dev.py clean
84119

85-
# Use enums
86-
status = workflow.WORKFLOW_EXECUTION_CLOSE_STATUS_COMPLETED
120+
# Run all checks (lint + test)
121+
uv run python scripts/dev.py check
87122
```
88123

89124
## License

cadence/api/v1/__init__.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Auto-generated __init__.py file
2-
# Import all generated protobuf modules
2+
# Import all generated protobuf and gRPC modules
33
from . import common_pb2
44
from . import decision_pb2
55
from . import domain_pb2
@@ -14,6 +14,20 @@
1414
from . import tasklist_pb2
1515
from . import visibility_pb2
1616
from . import workflow_pb2
17+
from . import common_pb2_grpc
18+
from . import decision_pb2_grpc
19+
from . import domain_pb2_grpc
20+
from . import error_pb2_grpc
21+
from . import history_pb2_grpc
22+
from . import query_pb2_grpc
23+
from . import service_domain_pb2_grpc
24+
from . import service_meta_pb2_grpc
25+
from . import service_visibility_pb2_grpc
26+
from . import service_worker_pb2_grpc
27+
from . import service_workflow_pb2_grpc
28+
from . import tasklist_pb2_grpc
29+
from . import visibility_pb2_grpc
30+
from . import workflow_pb2_grpc
1731

1832
# Create cleaner aliases for easier imports
1933
common = common_pb2
@@ -30,8 +44,22 @@
3044
tasklist = tasklist_pb2
3145
visibility = visibility_pb2
3246
workflow = workflow_pb2
47+
common_grpc = common_pb2_grpc
48+
decision_grpc = decision_pb2_grpc
49+
domain_grpc = domain_pb2_grpc
50+
error_grpc = error_pb2_grpc
51+
history_grpc = history_pb2_grpc
52+
query_grpc = query_pb2_grpc
53+
service_domain_grpc = service_domain_pb2_grpc
54+
service_meta_grpc = service_meta_pb2_grpc
55+
service_visibility_grpc = service_visibility_pb2_grpc
56+
service_worker_grpc = service_worker_pb2_grpc
57+
service_workflow_grpc = service_workflow_pb2_grpc
58+
tasklist_grpc = tasklist_pb2_grpc
59+
visibility_grpc = visibility_pb2_grpc
60+
workflow_grpc = workflow_pb2_grpc
3361

34-
# Only expose clean module names (no _pb2)
62+
# Only expose clean module names
3563
__all__ = [
3664
'common',
3765
'decision',
@@ -47,4 +75,18 @@
4775
'tasklist',
4876
'visibility',
4977
'workflow',
78+
'common_grpc',
79+
'decision_grpc',
80+
'domain_grpc',
81+
'error_grpc',
82+
'history_grpc',
83+
'query_grpc',
84+
'service_domain_grpc',
85+
'service_meta_grpc',
86+
'service_visibility_grpc',
87+
'service_worker_grpc',
88+
'service_workflow_grpc',
89+
'tasklist_grpc',
90+
'visibility_grpc',
91+
'workflow_grpc',
5092
]

cadence/api/v1/common_pb2_grpc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2+
"""Client and server classes corresponding to protobuf-defined services."""
3+
import grpc
4+
import warnings
5+
6+
7+
GRPC_GENERATED_VERSION = '1.71.2'
8+
GRPC_VERSION = grpc.__version__
9+
_version_not_supported = False
10+
11+
try:
12+
from grpc._utilities import first_version_is_lower
13+
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
14+
except ImportError:
15+
_version_not_supported = True
16+
17+
if _version_not_supported:
18+
raise RuntimeError(
19+
f'The grpc package installed is at version {GRPC_VERSION},'
20+
+ f' but the generated code in cadence/api/v1/common_pb2_grpc.py depends on'
21+
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
22+
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
23+
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
24+
)

cadence/api/v1/decision_pb2_grpc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2+
"""Client and server classes corresponding to protobuf-defined services."""
3+
import grpc
4+
import warnings
5+
6+
7+
GRPC_GENERATED_VERSION = '1.71.2'
8+
GRPC_VERSION = grpc.__version__
9+
_version_not_supported = False
10+
11+
try:
12+
from grpc._utilities import first_version_is_lower
13+
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
14+
except ImportError:
15+
_version_not_supported = True
16+
17+
if _version_not_supported:
18+
raise RuntimeError(
19+
f'The grpc package installed is at version {GRPC_VERSION},'
20+
+ f' but the generated code in cadence/api/v1/decision_pb2_grpc.py depends on'
21+
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
22+
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
23+
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
24+
)

cadence/api/v1/domain_pb2_grpc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2+
"""Client and server classes corresponding to protobuf-defined services."""
3+
import grpc
4+
import warnings
5+
6+
7+
GRPC_GENERATED_VERSION = '1.71.2'
8+
GRPC_VERSION = grpc.__version__
9+
_version_not_supported = False
10+
11+
try:
12+
from grpc._utilities import first_version_is_lower
13+
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
14+
except ImportError:
15+
_version_not_supported = True
16+
17+
if _version_not_supported:
18+
raise RuntimeError(
19+
f'The grpc package installed is at version {GRPC_VERSION},'
20+
+ f' but the generated code in cadence/api/v1/domain_pb2_grpc.py depends on'
21+
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
22+
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
23+
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
24+
)

cadence/api/v1/error_pb2_grpc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2+
"""Client and server classes corresponding to protobuf-defined services."""
3+
import grpc
4+
import warnings
5+
6+
7+
GRPC_GENERATED_VERSION = '1.71.2'
8+
GRPC_VERSION = grpc.__version__
9+
_version_not_supported = False
10+
11+
try:
12+
from grpc._utilities import first_version_is_lower
13+
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
14+
except ImportError:
15+
_version_not_supported = True
16+
17+
if _version_not_supported:
18+
raise RuntimeError(
19+
f'The grpc package installed is at version {GRPC_VERSION},'
20+
+ f' but the generated code in cadence/api/v1/error_pb2_grpc.py depends on'
21+
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
22+
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
23+
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
24+
)

cadence/api/v1/history_pb2_grpc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2+
"""Client and server classes corresponding to protobuf-defined services."""
3+
import grpc
4+
import warnings
5+
6+
7+
GRPC_GENERATED_VERSION = '1.71.2'
8+
GRPC_VERSION = grpc.__version__
9+
_version_not_supported = False
10+
11+
try:
12+
from grpc._utilities import first_version_is_lower
13+
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
14+
except ImportError:
15+
_version_not_supported = True
16+
17+
if _version_not_supported:
18+
raise RuntimeError(
19+
f'The grpc package installed is at version {GRPC_VERSION},'
20+
+ f' but the generated code in cadence/api/v1/history_pb2_grpc.py depends on'
21+
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
22+
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
23+
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
24+
)

cadence/api/v1/query_pb2_grpc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
2+
"""Client and server classes corresponding to protobuf-defined services."""
3+
import grpc
4+
import warnings
5+
6+
7+
GRPC_GENERATED_VERSION = '1.71.2'
8+
GRPC_VERSION = grpc.__version__
9+
_version_not_supported = False
10+
11+
try:
12+
from grpc._utilities import first_version_is_lower
13+
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
14+
except ImportError:
15+
_version_not_supported = True
16+
17+
if _version_not_supported:
18+
raise RuntimeError(
19+
f'The grpc package installed is at version {GRPC_VERSION},'
20+
+ f' but the generated code in cadence/api/v1/query_pb2_grpc.py depends on'
21+
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
22+
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
23+
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
24+
)

0 commit comments

Comments
 (0)