Command: init_grpc
Initializes base gRPC scaffold inside Django app(s).
Basic usage:
python manage.py init_grpc --app products
If no flags are provided, command behaves as --all.
What Command Creates
For each target app it creates:
<app>/grpc/__init__.py<app>/grpc/services.py<app>/grpc/proto/__init__.py
These files are the minimal structure required to start defining services and generating proto.
Options
--app <label>: target app label; can be repeated--all: scaffold every installed app--force: overwrite existing scaffold files
Examples:
# single app
python manage.py init_grpc --app products
# multiple explicit apps
python manage.py init_grpc --app products --app billing
# all installed apps
python manage.py init_grpc --all
# rewrite existing files
python manage.py init_grpc --app products --force
Output Behavior
Command prints one line per file:
write <path>when file is created/overwrittenskip <path>when file exists and--forceis not set
Final summary:
gRPC scaffold complete. created=<N> skipped=<M>
Validation Rules
--alland--appcannot be used together.- Unknown app labels produce
CommandError. - If no matching apps found, command fails.
Typical errors:
Use either --all or --app, not both.Unknown app label(s): ...No matching apps found.
Recommended Workflow
- Run
init_grpcfor your app. - Implement services in
<app>/grpc/services.py. - Run
generate_proto. - Start server with
run_grpcserver.
Example:
python manage.py init_grpc --app products
python manage.py generate_proto --app products --force
python manage.py run_grpcserver --bind 0.0.0.0:50051 --health --reflection
Notes on --force
--force overwrites scaffold files, so use it carefully if those files were already customized.
Safe approach:
- commit changes before rerunning with
--force - rerun command
- restore/merge your custom code if needed