flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Unable to generate GRPC interface for Python?

Open JaydenFish opened this issue 1 year ago • 9 comments

Do I have to use protobuf with grpc? flatc version 24.3.25 with a simple fbs:

namespace models;

table HelloReply {
  message:string;
}

table HelloRequest {
  name:string;
}

table ManyHellosRequest {
  name:string;
  num_greetings:int;
}

rpc_service Greeter {
  SayHello(HelloRequest):HelloReply;
  SayManyHellos(ManyHellosRequest):HelloReply (streaming: "server");
}

and run flatc -c -p --grpc -o api/ include/fbs/greeter.fbs output is

error:
  Unable to generate GRPC interface for Python

JaydenFish avatar May 30 '24 09:05 JaydenFish

I tried to reproduce this and build tags/v24.3.25. and your example works fine for me.

$ cat include/fbs/greeter.fbs
namespace models;

table HelloReply {
  message:string;
}

table HelloRequest {
  name:string;
}

table ManyHellosRequest {
  name:string;
  num_greetings:int;
}

rpc_service Greeter {
  SayHello(HelloRequest):HelloReply;
  SayManyHellos(ManyHellosRequest):HelloReply (streaming: "server");
}
$ ../flatc -c -p -o api/ include/fbs/greeter.fbs
$ ls
api  include

fliiiix avatar Jun 02 '24 10:06 fliiiix

I tried to reproduce this and build tags/v24.3.25. and your example works fine for me.

$ cat include/fbs/greeter.fbs
namespace models;

table HelloReply {
  message:string;
}

table HelloRequest {
  name:string;
}

table ManyHellosRequest {
  name:string;
  num_greetings:int;
}

rpc_service Greeter {
  SayHello(HelloRequest):HelloReply;
  SayManyHellos(ManyHellosRequest):HelloReply (streaming: "server");
}
$ ../flatc -c -p -o api/ include/fbs/greeter.fbs
$ ls
api  include

This is not with grpc.

JaydenFish avatar Jun 03 '24 10:06 JaydenFish

Looks like flatbuffer+grpc doesn't support python. I fallback to probobuf.

JaydenFish avatar Jun 03 '24 10:06 JaydenFish

Ahh you didn't add --grpc in your initial bug report image

but yeah with this flag i can reproduce it :+1:

Looks like flatbuffer+grpc doesn't support python.

I don't think that is true we use flatbuffer with grpc at work :sweat_smile:

I think it's just broken in a recent version if it wouldn't be supported the error message is more along the lines of GRPC interface generator not implemented for

fliiiix avatar Jun 03 '24 10:06 fliiiix

@JaydenFish

Hey, thanks for opening this issue. I think there is a known issue with python with directories which can be found here: https://github.com/google/flatbuffers/pull/8074

However following your own example:

Using the following flag flatc -c -p --grpc api/include/fbs/m.fbs. I removed the -o flag since its the cause of the issue to begin with, and the spacing between api/ include.

mustiikhalil avatar Jun 03 '24 10:06 mustiikhalil

Thanks!

JaydenFish avatar Jun 03 '24 17:06 JaydenFish

图片 Sometimes it go wrong. Sometime it works correctly. It's weird. 图片

I have a Makefile about fbs:

%.grpc.fb.h: %.fbs
    flatc -c --grpc -o $(dir $*) $^
    flatc -p --grpc -o api       $^
    prename 's/\.cc$//.cpp/' $(dir $*)*.cc

JaydenFish avatar Jun 04 '24 02:06 JaydenFish

And this is weird. The command specify write output to pyapi and generated, but it generate helloworld_grpc_fb.py in current dir. 图片

JaydenFish avatar Jun 04 '24 09:06 JaydenFish

I finaly got around to test the new .pyi generation. And I seen similar problems with the generation of the grpc file. (see: https://github.com/google/flatbuffers/pull/8356)

Didn't got around to test with https://github.com/google/flatbuffers/pull/8074 since it would need to be rebased on master which did not look straight forward to me

fliiiix avatar Jul 06 '24 14:07 fliiiix

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Jan 04 '25 20:01 github-actions[bot]

not-stale

fliiiix avatar Jan 04 '25 20:01 fliiiix

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Jul 06 '25 20:07 github-actions[bot]

@JaydenFish Is this still an issue for you or can this be closed?

As far as i can tell on the latest master the grpc file (greeter_grpc_fb.py) is generated again see:

flatc -c -p --grpc -o api/ include/fbs/greeter.fbs
ls api/models/
greeter_grpc_fb.py  HelloReply.py  HelloRequest.py  __init__.py  ManyHellosRequest.py

fliiiix avatar Jul 27 '25 18:07 fliiiix