Turns your Python functions into microservices with web API, interactive GUI, and more.
Getting Started β’ Features β’ Examples β’ Support β’ Report a Bug β’ Contribution β’ Changelog
Instantly 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 playground here.
Requirements: Python 3.6+.
bash
pip install opyrator
A simple Opyrator-compatible function could look like this:
```python from pydantic import BaseModel
class Input(BaseModel): message: str
class Output(BaseModel): message: str
def hello_world(input: Input) -> Output:
"""Returns the message
of the input data."""
return Output(message=input.message)
```
π‘ An Opyrator-compatible function is required to have an input
parameter and return value based on Pydantic models. The input and output models are specified via type hints.
Copy this code to a file, e.g. my_opyrator.py
Run the UI server from command-line:
bash
opyrator launch-ui my_opyrator:hello_world
In 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:
bash
opyrator launch-api my_opyrator:hello_world
In 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 the Features section or get inspired by our examples.
π Try out and explore these examples in our playground here
The 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:
bash
docker run -p 8080:8080 mltooling/opyrator-playground:latest
This project is maintained by Benjamin RΓ€thlein, Lukas Masuch, and Jan 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.
| Type | Channel |
| ------------------------ | ------------------------------------------------------ |
| π¨ Bug Reports | |
| π Feature Requests |
|
| π©βπ» Usage Questions |
|
| π’ Announcements |
|
| β Other Requests |
|
HTTP API β’ Graphical UI β’ CLI β’ Zip Export β’ Docker Export β’ Pre-defined Components β’ Production Deployment
With Opyrator, you can instantly launch a local HTTP (REST) API server for any compatible function:
bash
opyrator launch-api my_opyrator:hello_world
This will launch a FastAPI server based on the OpenAPI standard and 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:
bash
opyrator launch-api my_opyrator:hello_world --port 8080
The API server can also be started via the exported zip-file format (see zip export section below).
bash
opyrator launch-api my-opyrator.zip
You can launch a graphical user interface - powered by Streamlit - for your compatible function. The UI is auto-generated from the input- and output-schema of the given function.
bash
opyrator launch-ui my_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 the input- and output-schema section.
The port used by the UI server can be provided via CLI arguments:
bash
opyrator launch-ui my_opyrator:hello_world --port 8080
The UI server can also be started via the exported zip-file format (see zip export section below).
bash
opyrator launch-ui my-opyrator.zip
In addition, the UI server can be started by using an already running Opyrator API endpoint:
bash
opyrator launch-ui http://my-opyrator:8080
Thereby, all Opyrator calls from the UI will be executed via the configured HTTP endpoint instead of the Python function running inside the UI server.
An Opyrator can also be executed via command-line:
bash
opyrator call my_opyrator:hello_world '{"message": "hello"}'
The CLI interface also works using the zip export format:
bash
opyrator call my-opyrator.zip '{"message": "hello"}'
Or, by using an already running Opyrator API endpoint:
bash
opyrator call http://my-opyrator:8080 '{"message": "hello"}'
Thereby, the function call is executed by the Opyrator API server, instead of locally using the Python function.
Opyrator allows you to package and export a compatible function into a self-contained zip-file:
bash
opyrator export my_opyrator:hello_world my-opyrator.zip
This 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 via pipreqs as 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 the Docker or pex export 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:
bash
pip install my-opyrator.zip
WIP: This feature is not finalized yet. You can track the progress and vote for the feature here
In addition to the ZIP export, Opyrator also provides the capability to export to a Docker image:
bash
opyrator export my_opyrator:hello_world --format=docker my-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:
bash
docker run -p 8080:8080 my-opyrator-image:latest
Running 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 feature here.
Opyrator also provides the capability to export to a pex-file. Pex is a tool to create self-contained executable Python environments that contain all relevant python dependencies.
bash
opyrator export my_opyrator:hello_world --format=pex my-opyrator.pex
WIP: This feature is not finalized yet. You can track the progress and vote for the feature here.
Every deployed Opyrator provides a Python client library via an endpoint method which can be installed with pip:
bash
pip install http://my-opyrator:8080/client
And used in your code, as shown below:
python
from my_opyrator import Client, Input
opyrator_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 feature here.
Opyrator 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 the examples section or in this source code package.
WIP: This feature is not finalized yet. You can track the progress and vote for the feature here.
Rolling 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:
bash
opyrator deploy my_opyrator:hello_world <deployment-provider> <deployment-provider-options>
WIP: This feature is not finalized yet. You can track the progress and vote for the feature here.
A function is compatible with Opyrator if it fulfills the following requirements:
input
which MUST be a subclass of the Pydantic BaseModel.input
parameter and return value MUST be annotated with Python typing hints.WIP
WIP
Refer to our contribution guides for information on our build scripts and development process.
Licensed MIT. Created and maintained with β€οΈ by developers from Berlin.
Bumps starlette from 0.13.6 to 0.25.0.
Sourced from starlette's releases.
Version 0.25.0
Fixed
- Limit the number of fields and files when parsing
multipart/form-data
on theMultipartParser
8c74c2c and #2036.Version 0.24.0
Added
- Allow
StaticFiles
to follow symlinks #1683.- Allow
Request.form()
as a context manager #1903.- Add
size
attribute toUploadFile
#1405.- Add
env_prefix
argument toConfig
#1990.- Add template context processors #1904.
- Support
str
anddatetime
onexpires
parameter on theResponse.set_cookie
method #1908.Changed
- Lazily build the middleware stack #2017.
- Make the
file
argument required onUploadFile
#1413.- Use debug extension instead of custom response template extension #1991.
Fixed
- Fix url parsing of ipv6 urls on
URL.replace
#1965.Version 0.23.1
Fixed
- Only stop receiving stream on
body_stream
if body is empty on theBaseHTTPMiddleware
#1940.Version 0.23.0
Added
- Add
headers
parameter to theTestClient
#1966.Deprecated
- Deprecate
Starlette
andRouter
decorators #1897.Fixed
- Fix bug on
FloatConvertor
regex #1973.Version 0.22.0
Changed
- Bypass
GZipMiddleware
when response includesContent-Encoding
#1901.Fixed
- Remove unneeded
unquote()
from query parameters on theTestClient
#1953.- Make sure
MutableHeaders._list
is actually alist
#1917.- Import compatibility with the next version of
AnyIO
#1936.Version 0.21.0
This release replaces the underlying HTTP client used on the
TestClient
(requests
:arrow_right:httpx
), and as those clients differ a bit on their API, your test suite will likely break. To make the migration smoother, you can use thebump-testclient
tool.Changed
- Replace
requests
withhttpx
inTestClient
#1376.
... (truncated)
Sourced from starlette's changelog.
0.25.0
February 14, 2023
Fix
- Limit the number of fields and files when parsing
multipart/form-data
on theMultipartParser
8c74c2c and #2036.0.24.0
February 6, 2023
Added
- Allow
StaticFiles
to follow symlinks #1683.- Allow
Request.form()
as a context manager #1903.- Add
size
attribute toUploadFile
#1405.- Add
env_prefix
argument toConfig
#1990.- Add template context processors #1904.
- Support
str
anddatetime
onexpires
parameter on theResponse.set_cookie
method #1908.Changed
- Lazily build the middleware stack #2017.
- Make the
file
argument required onUploadFile
#1413.- Use debug extension instead of custom response template extension #1991.
Fixed
- Fix url parsing of ipv6 urls on
URL.replace
#1965.0.23.1
December 9, 2022
Fixed
- Only stop receiving stream on
body_stream
if body is empty on theBaseHTTPMiddleware
#1940.0.23.0
December 5, 2022
Added
- Add
headers
parameter to theTestClient
#1966.Deprecated
- Deprecate
Starlette
andRouter
decorators #1897.Fixed
- Fix bug on
FloatConvertor
regex #1973.0.22.0
November 17, 2022
... (truncated)
fc48089
Version 0.25.0 (#2035)bb4d8f9
π Close all the multipart files on error (#2036)8c74c2c
Merge pull request from GHSA-74m5-2c7w-9w3x5771a78
Fix test not passing in 32-bit architectures (#2033)337ae24
Document that UploadFile's filename
and content_type
can be None
(#2029)218a6b4
Version 0.24.0 (#1983)e05b632
Feature: Add size attribute to UploadFile (#1405)c568b55
allow using Request.form() as a context manager (#1903)0a63a6e
Support str
and datetime
on expires
parameter on the set_cookie
metho...94a22b8
Fix url parsing of ipv6 urls on URL.replace
(#1965)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Bumps ipython from 7.23.0 to 8.10.0.
15ea1ed
release 8.10.0560ad10
DOC: Update what's new for 8.10 (#13939)7557ade
DOC: Update what's new for 8.10385d693
Merge pull request from GHSA-29gw-9793-fvw7e548ee2
Swallow potential exceptions from showtraceback() (#13934)0694b08
MAINT: mock slowest test. (#13885)8655912
MAINT: mock slowest test.a011765
Isolate the attack tests with setUp and tearDown methodsc7a9470
Add some regression tests for this changefd34cf5
Swallow potential exceptions from showtraceback()Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Bumps cryptography from 3.4.7 to 39.0.1.
Sourced from cryptography's changelog.
39.0.1 - 2023-02-07
* **SECURITY ISSUE** - Fixed a bug where ``Cipher.update_into`` accepted Python buffer protocol objects, but allowed immutable buffers. **CVE-2023-23931** * Updated Windows, macOS, and Linux wheels to be compiled with OpenSSL 3.0.8.
.. _v39-0-0:
39.0.0 - 2023-01-01
- BACKWARDS INCOMPATIBLE: Support for OpenSSL 1.1.0 has been removed. Users on older version of OpenSSL will need to upgrade.
- BACKWARDS INCOMPATIBLE: Dropped support for LibreSSL < 3.5. The new minimum LibreSSL version is 3.5.0. Going forward our policy is to support versions of LibreSSL that are available in versions of OpenBSD that are still receiving security support.
- BACKWARDS INCOMPATIBLE: Removed the
encode_point
andfrom_encoded_point
methods on :class:~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicNumbers
, which had been deprecated for several years. :meth:~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.public_bytes
and :meth:~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey.from_encoded_point
should be used instead.- BACKWARDS INCOMPATIBLE: Support for using MD5 or SHA1 in :class:
~cryptography.x509.CertificateBuilder
, other X.509 builders, and PKCS7 has been removed.- BACKWARDS INCOMPATIBLE: Dropped support for macOS 10.10 and 10.11, macOS users must upgrade to 10.12 or newer.
- ANNOUNCEMENT: The next version of
cryptography
(40.0) will change the way we link OpenSSL. This will only impact users who buildcryptography
from source (i.e., not from awheel
), and specify their own version of OpenSSL. For those users, theCFLAGS
,LDFLAGS
,INCLUDE
,LIB
, andCRYPTOGRAPHY_SUPPRESS_LINK_FLAGS
environment variables will no longer be respected. Instead, users will need to configure their buildsas documented here
_.- Added support for :ref:
disabling the legacy provider in OpenSSL 3.0.x<legacy-provider>
.- Added support for disabling RSA key validation checks when loading RSA keys via :func:
~cryptography.hazmat.primitives.serialization.load_pem_private_key
, :func:~cryptography.hazmat.primitives.serialization.load_der_private_key
, and :meth:~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers.private_key
. This speeds up key loading but is :term:unsafe
if you are loading potentially attacker supplied keys.- Significantly improved performance for :class:
~cryptography.hazmat.primitives.ciphers.aead.ChaCha20Poly1305
... (truncated)
d6951dc
changelog + security fix backport (#8231)138da90
workaround scapy bug in downstream tests (#8218) (#8228)69527bc
bookworm is py311 now (#8200)111deef
backport main branch CI to 39.0.x (#8153)338a65a
39.0.0 version bump (#7954)84a3cd7
automatically download and upload circleci wheels (#7949)525c0b3
Type annotate release.py (#7951)46d2a94
Use the latest 3.10 release when wheel building (#7953)f150dc1
fix CI to work with ubuntu 22.04 (#7950)8867724
fix README for python3 (#7947)Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
Thanks to @JopaXd, @LukasMasuch and @raethlein for the contributions.
Thanks to @LukasMasuch, @adriangb and @raethlein for the contributions.
fastapi streamlit pydantic python microservices serverless faas functions python-functions machine-learning deployment type-hints