0% found this document useful (0 votes)
21 views74 pages

ODSC West - Creating APIs That Data Scientists Will Love - With - Links

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views74 pages

ODSC West - Creating APIs That Data Scientists Will Love - With - Links

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

Github Repository for this presentation

{ AP
I}

{ API }

https://github.com/Ryandaydev/odsc-west-2024-1
Go deeper on today’s
topic with my book
coming From O'Reilly
Publishing in April 2025
Get more tips and tricks

Tip Sheet: APIs for AI &


Data Science - sign up today

https://tips.handsonapibook.com
A day in the life of a data scientist
How they spend their time

Creating APIs that data scientists will love


Agenda With Python coding examples

Q&A
Please save your questions for the end

Wrap-up Comments
What can you do next?

Ryan Day - 2024



To succeed in AI,
first master APIs.

— Ryan Day
Before you criticize a
man, walk a mile in his
shoes.
{ AP
I } I} That way, when you do
{ A P criticize him, you'll be a
mile away and have his

{ API } shoes
– Steve Martin

Marianna Diamos, Los Angeles Times, CC BY 4.0 via Wikimedia Commons


A day in the life
Ryan Day - 2024
of a data scientist
What jobs do data scientists do?
{ AP
I } I}
{ AP

{ API }

Ryan Day - 2024


Source: Anaconda State of Data Science Report, 2022
What Python tools do they use?
Ryan Day - 2024
Ryan Day - 2024
Creating APIs that data scientists will love
Our demonstration project

Ryan Day - 2024


Our demonstration project

Ryan Day - 2024


Tips to Make APIs for Data Scientists

1  Return data in JSON format.


2  Provide standard external identifiers.
3  Provide an SDK for your API
4  Enforce data type definitions.
5  Provide a method for bulk downloads.
6  Support querying by last changed date.

Ryan Day - 2024


Tip 1  Return data in JSON format

A common format that is easy to consume

Ryan Day - 2024


API Architecture

Ryan Day - 2024


Demo 1 Setting up FastAPI
Install dependencies

Ryan Day - 2024


Run Pytest to verify libraries installed

Ryan Day - 2024


https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/api/main.py

API code in main.py

Ryan Day - 2024


https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/api/main.py

FastAPI object and SQLAlchemy Database Connection

Ryan Day - 2024


https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/api/main.py

One API endpoint

Ryan Day - 2024


Running the API

Ryan Day - 2024


Players endpoint in Swagger UI documentation

Ryan Day - 2024


JSON data returned

Ryan Day - 2024


Tip 2  Provide standard external identifiers

Extra reference data to join other datasets.

Ryan Day - 2024


Ryan Day - 2024
Database Structure

Ryan Day - 2024


API Architecture

Ryan Day - 2024


Demo 2 Demonstrate data with external
identifier
https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/api/models.py

Using SQLAlchemy - defining models

Ryan Day - 2024


https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/api/crud.py

Using SQLAlchemy - querying database

Ryan Day - 2024


https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/api/main.py

Using SQLAlchemy - calling from FastAPI

Ryan Day - 2024


Tip 3  Provide a Software
Development Kit

SDKs: the easy button for users


Ryan Day - 2024
Demo 3 Python SDK
https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/sdk/src/swcpy/swc_client.py

Creating SDK client

Ryan Day - 2024


https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/sdk/src/swcpy/swc_config.pyf

Creating SDK configuration object

Ryan Day - 2024


https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/sdk/pyproject.toml

Using Pyproject to build and package the SDK

Ryan Day - 2024


https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/test_sdk.ipynb

Using SDK in a Jupyter Notebook

Ryan Day - 2024


Tip 4  Enforce data type definitions in your API.

Give structures your users can count on

Ryan Day - 2024


Demo 4 OpenAPI spec and Pydantic
API Architecture

Ryan Day - 2024


OpenAPI specification file

Ryan Day - 2024


OpenAPI specification file - paths
OpenAPI specification file - schemas
OpenAPI specification file - Players schema
https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/api/schemas.py

Pydantic - enforcing definitions

Ryan Day - 2024


Pydantic - FastAPI connecting data to Pydantic

Ryan Day - 2024


Tip 5  Provide a method for
bulk downloads.
The data, the whole data, and
nothing but the data.

Ryan Day - 2024


Q&A #2
Demo 5 SDK with bulk download
Bulk File - supporting CSV and Parquet
https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/sdk/src/swcpy/swc_client.py

Bulk File - accessing through SDK

Ryan Day - 2024


https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/sdk/src/swcpy/swc_client.py

Bulk File - individual file download

Ryan Day - 2024


Bulk File - userʼs perspective

Ryan Day - 2024


Tip 6  Support querying by last
changed date.

Just give me the deltas.

Ryan Day - 2024


Demo 6 Querying by last_changed_date
Last Changed Date - Userʼs perspective
Last Changed Date - FastAPI endpoint

Ryan Day - 2024


https://github.com/Ryandaydev/odsc-west-2024-1/blob/main/api/crud.py

Last Changed Date - SQLAlchemy query

Ryan Day - 2024


Tips to Make APIs for Data Scientists

1  Return data in JSON format.


2  Provide standard external identifiers.
3  Provide an SDK for your API
4  Enforce data type definitions.
5  Provide a method for bulk downloads.
6  Support querying by last changed date.

Ryan Day - 2024


Q&A #3
Wrap-Up
Get more tips and tricks

Tip Sheet: APIs for AI &


Data Science - sign up today

https://tips.handsonapibook.com
Credits
This presentation template is free for everyone to use thanks to the following:

for the presentation template

Pexels, Pixabay
for the photos

Happy designing!
Brand Name Contents Introduction Our Projects About Us March 15, 2024

Extra Slides
Focus on
hands-on
learning

https://addyo.substack.com/p/conquering-imposter-syndrome

You might also like