Transforming a Jupyter Notebook into an API service

Titan Tutorial #1: Hello World!

In this first tutorial, we will explain how to deploy the simplest imaginable Jupyter Notebook to illustrate how easy is to transform models into services using Titan, our flagship product at Akoios. Let’s get started!

First step to get started is to open the Jupyter Notebook editor of your choice (Anaconda Distribution, Google Colab or any other).

Now, we are ready to write a very simple Python code in one of the notebook cells (no imports needed!):

A very simple cell printing Hello world

The code in the cell just prints “Hello world!” when executed. Imagine now that you want to make this available as a service using a REST API interface.

Here is where Titan comes into play. Instrumentalizing a notebook with Titan is as easy as following these steps:

  • Select the HTTP method for the service (GET, PUT, POST, DELETE)
  • Define an arbitrary name for the endpoint

To define this it is just needed to write at the top of the cell we want to be executed every time the endpoints is called. To make it understandable for Titan, this information must be written after the comment character in Python.

“Instrumentalized” notebook

In this cell, we are telling Titan the following:

Execute everything in this cell every time someone makes a GET request to the /hello endpoint

Pretty simple, right?

Now that our “model” is ready, we can use Titan to transform it into a service. It’s as simple as running the command:

$ titan deploy
Running $ titan deploy

What we just did? When running $titan deploy this is what happens:

  • Titan shows you all the notebook files (*.ipynb) located in the current folder
  • You are requested to select one (helloworld.ipynb in our case)
  • Then, you are requested to select the desired runtime environment, we used the scipy for this simple example.

That’s all. Here’s where Titan starts doing its magic:

  • Build the project
  • Deploy the model
  • Start the service

By the end of the execution of the command, you will have a ready-to-use REST API endpoint located at a location like this:

https://your-domain-name/helloworld

Magic!

In order for an API to make sense, it must be easily accessed and well documented. In that sense, Titan includes a Swagger UI interface at that URL with relevant information about the API and the model. Swagger UI also allows to interact with the API’s resources:

Automagically-generated API description

You can even make a call to the endpoint clicking on the “Try it out” button!

After trying and, as expected, this is what you will get from the API call:

Server response. No surprises!

Let’s now try to consume the service from an external application like Postman. For an easy call like this one, it is just required to provide the following information:

Consuming the endpoint from Postman. Easy-peasy!

In case it helps, you can get the code in this repository.

Wrap-up

In this first edition of our series of tutorials we have seen how to seamlessly deploy a very simple piece of code using our product Titan. After that, we have seen how to consume the service straight from the Swagger UI interface and using Postman.

Next Tutorial

You can keep learning about how to use Titan in our next tutorial where we deploy our first ML model!

Foreword

Titan can help you to radically reduce and simplify the effort required to put AI/ML models into production, enabling Data Science teams to be agile, more productive and closer to the business impact of their developments.

If you want to know more about how to start using Titan or getting a free demo, please visit our website or drop us a line at info@akoios.com.

If you prefer, you can schedule a meeting with us here.

Akoios: Frictionless solutions for modern data science.

Akoios

Love podcasts or audiobooks? Learn on the go with our new app.

Five SOLID principles in Android

Geospatial indexing app with different backends using Spring Boot and Testcontainers

Using GitOps, Multiple Argo Instances, and Environments with Argo CD at Scale

Publish messages to dunglas/mercure from any PHP-Based Application including Laravel/Lumen…

How to change environment variables on Windows 10

How to fetch data from an API in Flutter

{UPDATE} Real Dubstep DJ Simulator Hack Free Resources Generator

The Best Of Programming on Medium (November 2021)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akoios

Akoios

Akoios

More from Medium

Modeling Staff Turnover for Retention Planning in Python

Photo by <a href=”https://unsplash.com/@lauradavidson?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Laura Davidson</a> on <a href=”https://unsplash.com/s/photos/office?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

How Important is Big Data in IoT

ETL for Rudderstack data in S3 using airflow

Implement strStr() — Leetcode Python Solution