Taking this statement is isolation, this isn’t that difficult. Build your API system using ordinary tools and ignore Docker; since you’re in a Python environment I’d suggest Flask as a base library for a REST API server, py.test as a unit-test library, and requests as a client library. Once you’ve built it and tested it (locally, in a Python virtual environment, without Docker) package it using Docker, run the image somewhere using
docker run -p ... to publish the API server’s port on the host machine, distribute the client library, and have users point the client at that host machine’s name and the port number you chose.
This isn’t how Docker is normally used, and “running a command” isn’t typically seen as the same as “calling a function”.
Say there was no Docker. How would you describe this problem? (For instance, what are you packaging, and what are its inputs and outputs?) How would you solve it without Docker?
For a setup like this, two more things are worth mentioning: Docker can be a little bit annoying to install and maintain and I’d hesitate to push it on people without the relevant experience; and since you must be root to run Docker images, you’re giving someone a lot of power over their system, especially if it’s a shared system.
The short real answer to your question is to use the Python subprocess library to run the long-winded
docker run command and collect its stdout, or to use a prepackaged Docker library to do the same thing, but again, you must be (effectively) root to run the script to do this.