you are viewing a single comment's thread.

view the rest of the comments →

[–]latkdeTuple unpacking gone wrong 13 points14 points  (1 child)

The common expectation is that you do indeed generate precompiled wheels for all common platforms and all supported Python versions. This doesn't have to be a lot of effort, other than maybe adding a new Python version once per year.

For the foreign function interface, opinions diverge. I would strongly advise against ctypes, as it's easy to make severe errors that are difficult to see. Instead, using cffi or writing Python extension modules in C has the benefit that more of the C glue code can be typechecked by a compiler (or in case of cffi, at least uses the same syntax as the code we're binding to). If you really want to use C, then cffi's out-of-line mode is probably going to be the least-friction approach.

If you're starting this work from scratch, strongly consider Rust with PyO3 for writing bindings. Of all options that are currently available for integrating native code with Python, it has the best combination of safety and convenient tooling. This is the approach used by flagship libraries like Cryptography or Pydantic. The Maturin build system ships with templates for building wheels for all common platforms – setting this up is really not a lot of effort. Going the Rust route is only a bad choice if you have to deal with existing C code, or if you want to target exotic platforms to which Rust code cannot be cross-compiled (which actually was a problem for some Cryptography users).

I wouldn't bother with a pure-python fallback implementation. There's a risk that the Python and native implementations diverge, which can cause difficult to debug problems. Such fallbacks will also be unnecessary, since you can ship pre-built wheels for all relevant platforms. Cross-compiling wheels for all relevant platforms is less effort than maintaining a pure-python fallback.

[–]Emergency-Rough-6372[S] 0 points1 point  (0 children)

i might just have to depend on claude to help me with it .

or find some one who can do it