Create a Daisi — The fastest way to deploy any Python code (including a full app !)
Daisi (app.daisi.io) is a scientific Cloud Computing platform running Python serverless functions, named Daisies. It is the foremost destination for APIs for Python coders, scientists, researchers, engineers, analysts.
In this post you will learn how to create a Daisi from a regular Python script with just a few click, get endpoints for every function of your code and add a beautiful UI with Streamlit.
Log in to Daisi
While browsing the content of app.daisi.io doesn't require an account, you will need to be logged in to create a new Daisi. Creating a new account is free and straight forward and you can actually connect your GitHub, Google or Microsoft account for an even faster process.
Pre requisites
- The Daisi platform will pull your code from a Github repository. So you would need to make sure that the version of the code that you want to deploy is up to date on GitHub.
- If you don’t have a Github account, you can still follow the steps below using one of our public templates. However, you will need to create a GitHub account to be able to deploy your own code later on.
A simple example
The code that we are going to deploy is short and simple but non trivial example. It computes the edges of an image using a function of the Scipy Python library. It will take in input a grayscale image and will return an edge image (original example from the Scipy Signal Processing documentation):
Nothing in the code here above makes it “cloud ready”. No endpoints definition with decorators or function handler. And we don’t need any of this to turn it into a Daisi : deploying this code as a live service on a serverless architecture in the Daisi platform is incredibly simple. It only requires to link its GitHub repository with the platform.
Here below is the step by step process:
- Click on “Create a New Daisi”, at the bottom right of the Daisi platform UI :
2. Enter the path to the GitHub repository :
use https://github.com/daisi-io/examples.git to work with a ready-to-go example
3. Select the branch, folder and main Python script. Click on “Create” :
4. The Daisi creation process starts immediately
During the Daisi creation, the following will happen:
- The Daisi platform will identify the Python packages needed to run your code, either from the
requirements.txt
file if present in the repository, or it will try to infer it from the imports in your script. Arequirements.txt
file is the recommended option since it will guarantee that the packages that are present in the file, and the version number specified, will be effectively installed. - A virtual environment is being created to run the code. Packages installation is performed automatically with
pip
. - During the installation, you can monitor the progress by opening the Daisi card and going to the Installation tab:
5. When the installation is complete, go to the Call It tab to discover how to call your Daisi with pydaisi
The Daisi platform has generated automatically endpoints for all function in your script, at the exception of classes methods, and a documentation on how to call them. If docstrings are present in you code, they are rendered as well in the auto generated doc:
Important note
To call this Daisi remotely without being authenticated, it needs to be publicly available. Make it Public by going to the “Settings” tab and clickling on the button “Make Public” in the “Visibility” section
If you wish to keep it private or share it inside a team only, you will need a Personal Access Token. Please check the Authentication section in our docs.
Daisies can be called from any environment in which it is possible to run HTTP requests. From a Python code, the pydaisi
package makes Daisies calls as straight forward as if they were local functions, passing arbitrary Python objects in argument and receiving whatever the function returns.
With pydaisi
, no need to think about data serialization or writing HTTP requests, etc… it is entirely abstracted and the Daisi platform becomes a straight extension of your workspace !
Calling remotely the endpoint for the compute_deriv()
function with pydaisi
is as follows:
Notes:
- Any Daisi can be called uniquely with the pattern “username/daisiname”. This means that a given user can’t create two Daisies with the same name.
- With
pydaisi
, aDaisi
object is created and makes reference to the deployed Daisi in the platform - All functions of the main script can be called as methods of the Daisi object.
- For instance, in the example above, the
Daisi
object is instanciated asedge_image_computation
. We can trigger the execution of the functioncompute_deriv()
by simply calling it as a method ofedge_image_computation
:edge_image_computation.compute_deriv()
- We can pass the arguments that this function requires as if it were a local function. In this case, it will takes in input an image as a 2D bumpy array, that we can pass directly.
- Calling
edge_image_computation.compute_deriv()
will return an execution object with different attributes, such as the execution status, the execution logs, etc… (See our docs at doc.daisi.io). If we want to get immediately the data returned by the function, we can call the.value
attribute. The complete call in this case is simply:
edge_image_computation.compute_deriv().value
Update your Daisi and add a UI with Streamlit
The Daisi platform can render a front-end developed with Streamlit. More frameworks will be supported down the road. This is a great way to let your users test and understand what your Daisies can do.
When you import
streamlit
in your code, the button Launch the app will be active in the Daisi page on app.daisi.io as well as the Try it button on the Daisi card in the catalog.
We can build a simple UI by adding the following function:
Note that we add a if __name__ == "__main__"
block statement to call the st_ui()
function. This is required to effectively render the Streamlit app.
Updating your Daisi simply takes the following steps:
- Push the updated code in your GitHub repository
- In the Daisi page, go to the Settings tab and click on “Synchronize”:
The “Try it” button in the upper right corner of the Daisi page is now active and you can immediately launch the app and test the Daisi interactively !
Congratulations ! You have now a fully deployed Python code as a serverless microservice which can be called from anywhere. And it has a nice front-end that you can share as well.
For a look at some Daisies that are ready to be called on the platform, please check our growing catalog on app.daisi.io !
What’s next ?
Daisi is the missing “Cloud button”, making the cloud a straight extension of any scientist or engineer workspace. It empowers you to be your own Ops ! Here are just a few examples of what you can do with Daisi:
- Deploy a ML model
- Create and orchestrate the backend of a web app with Daisies as microservices
- Orchestrate workflows, including ETL workflows since Daisies plug in naturally with packages like Airflow or Prefect
- Deploy simple web apps coded in Python and give them an API for computer access at the same time
- Accelerate tasks by running hundreds of instances of a Daisi in parallel (see our docs, this feature is still in development)
- And not forgetting than Daisies can be called from anywhere, including from other Daisies. Making reuse and remix incredibly easy !
Some Frequently Asked Questions
What if I want to share a Daisi (publicly or within a team) but I don’t want to expose the source code ?
If your code is from a private GitHub repository, it will not be visible by anyone in the Daisi platform.
What about data access ?
You can access any data source from a Daisi as long as the data can be queried with HTTP requests. Secrets management is under development and will be available soon.
My code needs to access large files, which I can’t store on GitHub (for instance a ML model)
We are currently developing the ability to add additional resources to a Daisi, beyond what is inside the GitHub repository.
My Daisi needs to load in memory a large amount of data
The amount of data to load in memory is not an issue up to 5Gbs in the free version of the Daisi platform.
Can you choose the type of hardware on which Daisies execute ?
Soon, you will be offered the choice of hardware at runtime, including GPUs.