Earn Money with Machine Learning by Deploying an API | by Garrett Eichhorn | Towards Data Science

If you’re reading this, it’s because you’ve created some valuable code that you’re hoping to publish. Whether you simply packaged together some open-source technology or built a brilliant new algorithm, there’s a good chance that other technologists will find your solution useful.
In this article, you’ll leverage open-source frameworks to deploy your pride-and-joy to an API marketplace in 3 simple steps. You might even earn a little passive income. It takes a bit of work and a stroke of luck to elicit high praise and/or profits — let’s shoot our shot 🏀!
As a talented data professional, you’re well acquainted with APIs. Here are a few of my favorites if you need a quick refresher:
towardsdatascience.com
An API marketplace allows developers to publish and monetize their work, without having to curate custom payment systems and complicated infrastructure. RapidAPI is my favorite, featuring ‘freemium’ and paid subscription plans for every type of API you can imagine. Let’s say you’re building a custom application that correlates financial data with COVID-19 infection statistics, you’d use RapidAPI to discover, learn and scale.
The open-source-software movement fuels some of the most beloved, lucrative tech companies in the world. Open-source scripting languages (Python, R, Julia), database technology (SQL, MongoDB) and computing libraries (SciPi, Scikit-learn, tidyr) exist to empower the growing number of data professionals in building valuable solutions at variable scale. Why not contribute to an amazing ecosystem of developer resources?
If you’re a burgeoning data scientist, there’s no better way to market your talent and entrepreneurial skillset. Let’s get started!
There are multiple ways to get an API up-and-running. Here are a few of my favorites for python deployment:
Deploy a Serverless Web App on AWS Lambda with ZappaBuild a Simple Web App with GitHub Pages, Flask and HerokuUse FastAPI and Uvicorn (we’ll be using this method😉)
Deploy a Serverless Web App on AWS Lambda with Zappa
Build a Simple Web App with GitHub Pages, Flask and Heroku
Use FastAPI and Uvicorn (we’ll be using this method😉)
FastAPI is a lightning fast, intuitive and robust API framework that simplifies the development process. Uvicorn is a popular WSGI Server that makes it easy to run python applications in the cloud.
I recently developed a simple program to grab text from a news article, process the text for Named Entity Recognition and Part of Speech Tagging, then perform some advanced analysis.
Install dependencies:
Install dependencies:
pip install fastapi uvicorn gunicorn
2. Format endpoints.
Take a look at the path params documentation before formatting your code:
3. Run it!
uvicorn main:app --reload
4. Review (generated) documentation in Swagger UI:
http://127.0.0.1:8000/docs
5. Take the API for a spin!
Save your code to a GitHub repository.Open Heroku, create a new app, connect your GitHub account, link the specific repository you’d like to publish, and enable automatic deployments.Build a requirements.txt file by running the following:
Save your code to a GitHub repository.
Open Heroku, create a new app, connect your GitHub account, link the specific repository you’d like to publish, and enable automatic deployments.
Build a requirements.txt file by running the following:
pip freeze > requirements.txt
4. Make a Procfile so Heroku knows how to deploy the app:
web: gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app
5. Push to GitHub and wait for Heroku to deploy your solution! You can view my finished examples below for appropriate formatting👇
GitHub Repo
Heroku App
API Documentation
If you’re having trouble adding the local deployment to Heroku, check out this video!
Sign-up for a RapidAPI account and “Add a New API”.Add a base URL (link to Heroku app) and format relevant endpoints!Brand the API! Add a high-resolution image, eloquent descriptions and enticing features.Format pricing attributes for a Public Plan. RapidAPI offers multiple subscription plans that scale with consumption. Depending on your code, it might make sense to start with a completely free plan or free tier (‘freemium’ plan) to get other developers hooked. If you’re more confident, go straight to ‘paid’ and require a credit card with subscription.Finally, publish the API to the marketplace! Developers will be able to consume your brilliant new application and you’ll garner valuable feedback. Future updates / additional features will better serve those developers that consume your API.
Sign-up for a RapidAPI account and “Add a New API”.
Add a base URL (link to Heroku app) and format relevant endpoints!
Brand the API! Add a high-resolution image, eloquent descriptions and enticing features.
Format pricing attributes for a Public Plan. RapidAPI offers multiple subscription plans that scale with consumption. Depending on your code, it might make sense to start with a completely free plan or free tier (‘freemium’ plan) to get other developers hooked. If you’re more confident, go straight to ‘paid’ and require a credit card with subscription.
Finally, publish the API to the marketplace! Developers will be able to consume your brilliant new application and you’ll garner valuable feedback. Future updates / additional features will better serve those developers that consume your API.
A lot of APIs are developed by companies, rather than individuals. As the number of talented data professionals increases with demand, so will the demand for cheap, sophisticated alternatives for valuable algorithms and data pipelines. You may not earn passive income immediately, but you’re well on your way in showcasing unique talent and entrepreneurial spirit that improve your marketability while searching for data-related roles. I encourage you to play around with FastAPI and other alternatives to test the waters on what type of solutions are in high demand.
Connect with me if you want to discuss API formatting and best practice, open-source philosophy, or various in-demand software options you can develop. I’d love to hear from you.
Thanks for reading! 😃