Python Forum
library for C but written in Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: library for C but written in Python (/thread-41957.html)



library for C but written in Python - Skaperen - Apr-15-2024

has anyone here ever created a library for C but written in Python? i assume the hardest part is the arguments and their types. is there any particular documentation or developed code focusing on this aspect of development (making Python work to be a library that C code could call? on freedom i might expect is if the library API is being developed with this, it could focus on aspects on an API that can be easy in both languages (i.e.avoid the hard ways to pass args or provide C/Python layers to make this easier.


RE: library for C but written in Python - SandraYokum - Apr-15-2024

(Apr-15-2024, 02:47 AM)Skaperen Wrote: has anyone here ever created a library for C but written in Python? i assume the hardest part is the arguments and their types. is there any particular documentation or developed code focusing on this aspect of development (making Python work to be a library that C code could call? on freedom i might expect is if the library API is being developed with this, it could focus on aspects on an API that can be easy in both languages (i.e.avoid the hard ways to pass args or provide C/Python layers to make this easier.

When I was creating a C library using Python, I primarily used Cython to write Python code that compiles into a C extension. I referred to the Cython documentation extensively to handle data types and memory management correctly. Additionally, I made sure the API design was straightforward, using common data types and consistent error handling to bridge the two languages effectively.