go-python / cpy3

Go bindings to the CPython-3 API
MIT License
306 stars 50 forks source link

Convert go struct to dict #22

Open abemedia opened 2 years ago

abemedia commented 2 years ago

It would be great to have a helper function that converts a go struct or map to a Python dict.

As a matter of fact it would also be really useful to be able to convert other types, for example a function like ToPyObject which takes an interface and using reflection builds the relevant Python type.

A FromPyObject doing the reverse would be ideal too.

This would massively simplify interaction between Python and Go.

aadog commented 2 years ago

@abemedia your dream is complete

Let's try it, python bindings cgo-less

https://github.com/aadog/py3-go

christian-korneck commented 2 years ago

This is out of scope for the C-API bindidings. However, I'd be open to creating a pkg (within this module) with higher level abstractions on top of the base C-API bindings that help with common tasks, like importing a module or exchanging data. (The C-API bindings should continue to exist "untampered" however).

Would welcome PRs in that direction!

christian-korneck commented 2 years ago

@aadog Let's try it, python bindings cgo-less https://github.com/aadog/py3-go

thanks a lot, this looks like an amazing project, I will definitely try it. At a first look your project and this project don't seem to have exactly identical goals (for this project it's mainly C-API bindings that behave close to the original API - yours seems to have many more (which is quite exciting!)).

Any chance that you could clarify the license for your project? If it's compatible to this project, we might be able to steal from you. ;-)

aadog commented 2 years ago

@christian-korneck He doesn't have any restrictions, you can use it as you like

Toys written when you are bored, I wish you a good time

abemedia commented 2 years ago

I actually already did this in a fork. Happy to create a PR for it if it is acceptable. What shall I call the sub-package?

christian-korneck commented 2 years ago

sure, a PR for further discussion would be welcome. I’d say let’s call it helpers for now, we can still discuss naming.