Skip to content

API endpoint examples implemented in R (Plumber) and Python (FastAPI) with synthetic data generation

Notifications You must be signed in to change notification settings

DataBooth/api-endpoint-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api-endpoint-examples

Overview

This repository contains some RESTful API endpoint examples implemented in both:

There are 2 examples for each framework:

  1. Very simple APIs to echo the message provided and
  2. A simple credit risk modelling example (which uses some synthetically generated data to mimic a portfolio of home fixed and variable rate consumer home loans) with APIs to:
  • train the model using the synthetic data with 20% of the sample used for testing (/train)
  • predict the probability of default using specific features in the data (/predict) and
  • there is also an example of a simple healthcheck for the API (/healthcheck)

The credit risk modelling examples require data to train/test the logistic regression example model. Some brief background on the modelling is shown here docs/credit_modelling.md.

For both frameworks, in a local deployment, the endpoints are accessed at:

http://localhost:8000/endpoint_name.

A comparison of the two frameworks is available in docs/compare_plumber_fastapi.md.

R Examples (Plumber)

The R examples use the Plumber package to create API endpoints. These examples demonstrate:

  • Basic endpoint creation for displaying a simple message (simple.R and run_simple.R)
  • Credit risk modelling endpoints

View R examples

Python Examples (FastAPI)

The Python examples use the FastAPI framework to create endpoints by decorating methods. These examples showcase:

  • Basic endpoint creation for displaying a simple message (simple.py and simple.ipynb)
  • Credit risk modelling endpoints

View Python examples

Synthetic Data Generation

This data is generated in a Jupyter notebook in Python using the Faker package with the aim to produce a representative set of data. Note that only a sub-set of features is used in the modelling.

View Data Generation Notebook

Documentation

Each example includes auto-documentation via http://localhost:8000/docs for the R/Plumber APIs and http://localhost:8000/docs for the Python/FastAPI versions.

Additional documentation also describes how to set up and run the API.

API Testing

See docs/api_testing.md.

Getting Started

  1. Clone this repository:
  1. Navigate to the desired example directory.
  2. Follow the instructions in each subdirectory to set up and run the examples.

Prerequisites

  • R (version 4.0+) for Plumber examples
  • Python (version 3.7+) for FastAPI examples - see pyproject.toml for other environment details

Deployment

There are Dockerfiles supplied for both frameworks which an indicative set ot commands to build the containers.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

API endpoint examples implemented in R (Plumber) and Python (FastAPI) with synthetic data generation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published