google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
22.52k stars 3.19k forks source link

Unable to generate GRPC interface for Python? #8325

Open JaydenFish opened 1 month ago

JaydenFish commented 1 month ago

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
fliiiix commented 1 month ago

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
JaydenFish commented 1 month ago

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 commented 1 month ago

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

fliiiix commented 1 month ago

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

mustiikhalil commented 1 month ago

@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.

JaydenFish commented 1 month ago

Thanks!

JaydenFish commented 4 weeks ago

图片 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 commented 4 weeks ago

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