I maintain a Python 3 package (ocrmypdf) that works with other programs primarily by making subprocess calls. This is partly for historical reasons it is shell script that grew up.I have since added the amazing CFFI to access a C library that does not provide any executables, and I am looking for input on whether to convert other subprocess invocations to library API calls when both are available. Many open source programs are packaged as a library of common features and executable front-ends that exercises the library. (For example, if you were writing a program that worked on Git repositories, you could execute the git command line or bind to libgit.)It's easy to enumerate the pros and cons and subprocesses vs API binding in theory.Subprocesses:Isolation: Potentially unsafe third party code is executed in another process. Recovering from the failure of that process is easier. Library calls can be farmed out to a child process, but the complexity increases.Simplicity: Create temporary files, feed arguments to a command line, capture streams and output objects. This often happens at a higher level of functionality than initializing an API.Libraries:Control: Many libraries offer more direct control through their API than through an executable that access.Performance: In the subprocess approach intermediate data often needs to be serialized in some way. A program that works with libraries can often replace writing a temporary file with passing a pointer to memory.Explicit dependencies: Operating systems formally track executable to library dependencies, but never track that one executable sometimes calls another executable.Consistency: The porcelain changes more often than the plumbing. Command line programs frequently change their output. Changes that break output parsers can occur regularly and without any warning, while developers are at least conscious about breaking their API.I'd particularly appreciate answers that are grounded in how this architecture change works out in practice.
Python: architecture implications of using external subprocess or API
python;packages;third party libraries