Package: opyrator
OpyratorTurns your Python functions into microservices with web API, interactive GUI, and more.Getting Started•Features•Examples•Support•Report a Bug•Contribution•ChangelogInstantly turn your Python functions into production-ready microservices. Deploy and access your services via HTTP API or interactive UI. Seamlessly export your services into portable, shareable, and executable files or Docker images. Opyrator builds on open standards - OpenAPI,  JSON Schema, and Python type hints - and is powered by FastAPI, Streamlit, and Pydantic. It cuts out all the pain for productizing and sharing your Python code - or anything you can wrap into a single Python function.Alpha Version: Only suggested for experimental usage.Try out and explore various examples in our playgroundhere.Highlights🪄  Turn functions into production-ready services within seconds.🔌  Auto-generated HTTP API based on FastAPI.🌅  Auto-generated Web UI based on Streamlit.📦  Save and share as self-contained executable file or Docker image.🧩  Reuse pre-defined components & combine with existing Opyrators.📈  Instantly deploy and scale for production usage.Getting StartedInstallationRequirements: Python 3.6+.pipinstallopyratorUsageA simple Opyrator-compatible function could look like this:frompydanticimportBaseModelclassInput(BaseModel):message:strclassOutput(BaseModel):message:strdefhello_world(input:Input)->Output:"""Returns the `message` of the input data."""returnOutput(message=input.message)💡 An Opyrator-compatible function is required to have aninputparameter and return value based onPydantic models. The input and output models are specified viatype hints.Copy this code to a file, e.g.my_opyrator.pyRun the UI server from command-line:opyratorlaunch-uimy_opyrator:hello_worldIn the output, there's a line that shows where your web app is being served, on your local machine.Run the HTTP API server from command-line:opyratorlaunch-apimy_opyrator:hello_worldIn the output, there's a line that shows where your web service is being served, on your local machine.Find out more usage information in theFeaturessection or get inspired by ourexamples.Examples👉  Try out and explore these examples in our playgroundhereThe following collection of examples demonstrate how Opyrator can support a variety of different tasks and use-cases. All these examples are bundled into a demo playground which you can also deploy on your own machine via Docker:dockerrun-p8080:8080mltooling/opyrator-playground:latestText Generation📄Source Code🌅UI Demo🔌OpenAPI SpecRun this demo on your machine (click to expand...)To run the demo on your local machine just execute the following commands:gitclonehttps://github.com/ml-tooling/opyratorcd./opyrator/examples/generate_text/
pipinstall-rrequirements.txt
opyratorlaunch-uiapp:generate_text--port8051Visithttp://localhost:8051in your browser to access the UI of the demo. Uselaunch-apiinstead oflaunch-uito launch the HTTP API server.Question Answering📄Source Code🌅UI Demo🔌OpenAPI SpecRun this demo on your machine (click to expand...)To run the demo on your local machine just execute the following commands:gitclonehttps://github.com/ml-tooling/opyratorcd./opyrator/examples/question_answering/
pipinstall-rrequirements.txt
opyratorlaunch-uiapp:question_answering--port8051Visithttp://localhost:8051in your browser to access the UI of the demo. Uselaunch-apiinstead oflaunch-uito launch the HTTP API server.Image Super Resolution📄Source Code🌅UI Demo🔌OpenAPI SpecRun this demo on your machine (click to expand...)To run the demo on your local machine just execute the following commands:gitclonehttps://github.com/ml-tooling/opyratorcd./opyrator/examples/image_super_resolution/
pipinstall-rrequirements.txt
opyratorlaunch-uiapp:image_super_resolution--port8051Visithttp://localhost:8051in your browser to access the UI of the demo. Uselaunch-apiinstead oflaunch-uito launch the HTTP API server.Text Preprocessing📄Source Code🌅UI Demo🔌OpenAPI SpecRun this demo on your machine (click to expand...)To run the demo on your local machine just execute the following commands:gitclonehttps://github.com/ml-tooling/opyratorcd./opyrator/examples/preprocess_text/
pipinstall-rrequirements.txt
opyratorlaunch-uiapp:preprocess_text--port8051Visithttp://localhost:8051in your browser to access the UI of the demo. Uselaunch-apiinstead oflaunch-uito launch the HTTP API server.Language Detection📄Source Code🌅UI Demo🔌OpenAPI SpecRun this demo on your machine (click to expand...)To run the demo on your local machine just execute the following commands:gitclonehttps://github.com/ml-tooling/opyratorcd./opyrator/examples/detect_language/
pipinstall-rrequirements.txt
opyratorlaunch-uiapp:detect_language--port8051Visithttp://localhost:8051in your browser to access the UI of the demo. Uselaunch-apiinstead oflaunch-uito launch the HTTP API server.Audio Separation📄Source Code🌅UI Demo🔌OpenAPI SpecRun this demo on your machine (click to expand...)To run the demo on your local machine just execute the following commands:gitclonehttps://github.com/ml-tooling/opyratorcd./opyrator/examples/separate_audio/
pipinstall-rrequirements.txt
opyratorlaunch-uiapp:separate_audio--port8051Visithttp://localhost:8051in your browser to access the UI of the demo. Uselaunch-apiinstead oflaunch-uito launch the HTTP API server.Word Vectors Training📄Source Code🌅UI Demo🔌OpenAPI SpecRun this demo on your machine (click to expand...)To run the demo on your local machine just execute the following commands:gitclonehttps://github.com/ml-tooling/opyratorcd./opyrator/examples/train_word_vectors/
pipinstall-rrequirements.txt
opyratorlaunch-uiapp:train_word_vectors--port8051Visithttp://localhost:8051in your browser to access the UI of the demo. Uselaunch-apiinstead oflaunch-uito launch the HTTP API server.Named Entity Recognition📄Source Code🌅UI Demo🔌OpenAPI SpecRun this demo on your machine (click to expand...)To run the demo on your local machine just execute the following commands:gitclonehttps://github.com/ml-tooling/opyratorcd./opyrator/examples/named_entity_recognition/
pipinstall-rrequirements.txt
opyratorlaunch-uiapp:named_entity_recognition--port8051Visithttp://localhost:8051in your browser to access the UI of the demo. Uselaunch-apiinstead oflaunch-uito launch the HTTP API server.Components Showcase📄Source Code🌅UI Demo🔌OpenAPI SpecRun this demo on your machine (click to expand...)To run the demo on your local machine just execute the following commands:gitclonehttps://github.com/ml-tooling/opyratorcd./opyrator/examples/showcase_components/
pipinstall-rrequirements.txt
opyratorlaunch-uiapp:showcase_components--port8051Visithttp://localhost:8051in your browser to access the UI of the demo. Uselaunch-apiinstead oflaunch-uito launch the HTTP API server.Support & FeedbackThis project is maintained byBenjamin Räthlein,Lukas Masuch, andJan Kalkan. Please understand that we won't be able to provide individual support via email. We also believe that help is much more valuable if it's shared publicly so that more people can benefit from it.TypeChannel🚨Bug Reports🎁Feature Requests👩‍💻Usage Questions📢Announcements❓Other RequestsFeaturesHTTP API•Graphical UI•CLI•Zip Export•Docker Export•Pre-defined Components•Production DeploymentHTTP APIWith Opyrator, you can instantly launch a local HTTP (REST) API server for anycompatible function:opyratorlaunch-apimy_opyrator:hello_worldThis will launch aFastAPIserver based on theOpenAPI standardand with an automatic interactive documentation.💡 Make sure that all requirements of your script are installed in the active Python enviornment.The port used by the API server can be provided via CLI arguments:opyratorlaunch-apimy_opyrator:hello_world--port8080The API server can also be started via the exported zip-file format (seezip export sectionbelow).opyratorlaunch-apimy-opyrator.zipGraphical UIYou can launch a graphical user interface - powered byStreamlit- for yourcompatible function. The UI is auto-generated from the input- and output-schema of the given function.opyratorlaunch-uimy_opyrator:hello_world💡 Make sure that all requirements of your script are installed in the active Python environment.You can influence most aspects of the UI just by changing and improving the input- and output-schema of your function. Furthermore, it is also possible to define custom UIs for the function's input and output. For more details, refer to theinput- and output-schemasection.The port used by the UI server can be provided via CLI arguments:opyratorlaunch-uimy_opyrator:hello_world--port8080The UI server can also be started via the exported zip-file format (seezip export sectionbelow).opyratorlaunch-uimy-opyrator.zipIn addition, the UI server can be started by using an already running Opyrator API endpoint:opyratorlaunch-uihttp://my-opyrator:8080Thereby, all Opyrator calls from the UI will be executed via the configured HTTP endpoint instead of the Python function running inside the UI server.Command-line InterfaceAn Opyrator can also be executed via command-line:opyratorcallmy_opyrator:hello_world'{"message": "hello"}'The CLI interface also works using thezip export format:opyratorcallmy-opyrator.zip'{"message": "hello"}'Or, by using an already running Opyrator API endpoint:opyratorcallhttp://my-opyrator:8080'{"message": "hello"}'Thereby, the function call is executed by the Opyrator API server, instead of locally using the Python function.Zip ExportOpyrator allows you to package and export acompatible functioninto a self-contained zip-file:opyratorexportmy_opyrator:hello_worldmy-opyrator.zipThis exported zip-file packages relevant source code and data artifacts into a single file which can be shared, stored, and used for launching the API or UI as shown above.External requirements are automatically discovered from the working directory based on the following files:Pipfile(Pipenv environment),environment.yml(Conda environment),pyproject.toml(Poetry dependencies),requirements.txt(pip-requirements),setup.py(Python project requirements),packages.txt(apt-get packages), or discovered viapipreqsas fallback. However, external requirements are only included as instructions and are not packaged into the zip-file. If you want to export your Opyrator fully self-contained including all requirements or even the Python interpreter itself, please refer to theDockerorpexexport options.As a side note, Opyrators exported as zip-files are (mini) Python libraries that can be pip-installed, imported, and used from other Python code:pipinstallmy-opyrator.zipWIP: This feature is not finalized yet. You can track the progress and vote for the featurehereDocker ExportIn addition to the ZIP export, Opyrator also provides the capability to export to a Docker image:opyratorexportmy_opyrator:hello_world--format=dockermy-opyrator-image:latest💡 The Docker export requires that Docker is installed on your machine.After the successful export, the Docker image can be run as shown below:dockerrun-p8080:8080my-opyrator-image:latestRunning your Opyrator within this Docker image has the advantage that only a single port is required to be exposed. The separation between UI and API is done via URL paths:http://localhost:8080/api(API);http://localhost:8080/ui(UI). The UI is automatically configured to use the API for all function calls.WIP: This feature is not finalized yet. You can track the progress and vote for the featurehere.Pex ExportOpyrator also provides the capability to export to a pex-file.Pexis a tool to create self-contained executable Python environments that contain all relevant python dependencies.opyratorexportmy_opyrator:hello_world--format=pexmy-opyrator.pexWIP: This feature is not finalized yet. You can track the progress and vote for the featurehere.Python ClientEvery deployed Opyrator provides a Python client library via an endpoint method which can be installed with pip:pipinstallhttp://my-opyrator:8080/clientAnd used in your code, as shown below:frommy_opyratorimportClient,Inputopyrator_client=Client("http://my-opyrator:8080")result=opyrator_client.call(Input(text="hello",wait=1))WIP: This feature is not finalized yet. You can track the progress and vote for the featurehere.Pre-defined ComponentsOpyrator provides a growing collection of pre-defined components (input- and output models) for common tasks. Some of these components also provide more advanced UIs and Visualizations. You can reuse these components to speed up your development and, thereby, keep your Opyrators compatible with other functionality improvements or other Opyrators.You can find some of the available interfaces in theexamplessection or in thissource code package.WIP: This feature is not finalized yet. You can track the progress and vote for the featurehere.Production DeploymentRolling out your Opyrators for production usage might require additional features such as SSL, authentication, API tokens, unlimited scalability, load balancing, and monitoring. Therefore, we provide capabilities to easily  deploy your Opyrators directly on scalable and secure cloud platforms without any major overhead:opyratordeploymy_opyrator:hello_world<deployment-provider><deployment-provider-options>WIP: This feature is not finalized yet. You can track the progress and vote for the featurehere.DocumentationCompatible FunctionsA function is compatible with Opyrator if it fulfills the following requirements:A single parameter calledinputwhich MUST be a subclass of thePydantic BaseModel.A single return value that MUST be a subclass of thePydantic BaseModel.Theinputparameter and return value MUST be annotated with Python typing hints.Input- and Output-SchemaWIPCommand-line InterfaceWIPContributionPull requests are encouraged and always welcome. Read ourcontribution guidelinesand check outhelp-wantedissues.Submit Github issues for anyfeature request and enhancement,bugs, ordocumentationproblems.By participating in this project, you agree to abide by itsCode of Conduct.Thedevelopment sectionbelow contains information on how to build and test the project after you have implemented some changes.DevelopmentRefer to ourcontribution guidesfor information on our build scripts and development process.LicensedMIT. Created and maintained with ❤️  by developers from Berlin.