Skip to content

Commit

Permalink
Updates for presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryandaydev committed Oct 31, 2024
1 parent 354e1eb commit defcceb
Show file tree
Hide file tree
Showing 15 changed files with 882 additions and 263 deletions.
34 changes: 34 additions & 0 deletions example_sdk_notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using SDK in a Jupyter Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"from pyswc import SWCClient, SWCConfig\n",
"import pandas as pd\n",
"\n",
"config = SWCConfig()\n",
"client = SWCClient(config)\n",
"sdk_players = client.list_players()\n",
"\n",
"#convert the list of player instances to dictionaries\n",
"df = dp.DataFrame([player.model_dump() for player in sdk_players])\n",
"print(df)"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion notebooks_with_client/shark_league_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"logging.basicConfig(\n",
" filename='shark_notebook.log', \n",
" level=logging.INFO, \n",
")"
"\n",
"\n",
"logger = logging.getLogger(__name__) )"
]
},
{
Expand Down Expand Up @@ -77,6 +79,7 @@
"metadata": {},
"outputs": [],
"source": [
"logger.debug(f\"base_url: {base_url}, api_endpoint: {base_url,swc.LIST_WEEKS_ENDPOINT}\")\n",
"week_api_response = swc.call_api_endpoint(base_url,swc.LIST_WEEKS_ENDPOINT)\n",
"weeks_df = pd.DataFrame(week_api_response.json())\n",
"weeks_df['year'] = weeks_df['week_number'].str.slice(0, 4).astype(int)\n",
Expand Down
262 changes: 0 additions & 262 deletions notebooks_with_sdk/langgraph_notebook_with_toolkit.ipynb

This file was deleted.

48 changes: 48 additions & 0 deletions sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# swcpy software development kit (SDK)
This is the python SDK to to interact with the SportsWorldCentral Football API, which was created for the book [Hands-On APIs for AI and Data Science](https://hands-on-api-book.com).

## Installing swcpy

To install this SDK in your environment, execute the following command:

`pip install swcpy@git+https://github.com/{owner of repo}/portfolio-project#subdirectory=sdk`

## Example Usage

This SDK implements all the endpoints in the SWC API, in addition to providing bulk downloads of the SWC fantasy data in CSV format.

### Example of normal API functions

To call the SDK functions for normal API endpoints, here is an example:

```python
from swcpy import SWCClient
from swcpy import SWCConfig

config = SWCConfig(url="http://127.0.0.1:8000",backoff=False)
client = SWCClient(config)
leagues_response = client.list_leagues()
print(leagues_response)
```

### Example of bulk data functions

The build data endpoint return a bytes object. Here is an example of saving a file locally from a bulk file endpoint:

```python
import csv
import os
from io import StringIO

config = SWCConfig()
client = SWCClient(config)

"""Tests bulk player download through SDK"""
player_file = client.get_bulk_player_file()


# Write the file to disk to verify file download
output_file_path = data_dir + 'players_file.csv'
with open(output_file_path, 'wb') as f:
f.write(player_file)
```
25 changes: 25 additions & 0 deletions sdk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "swcpy"
version = "0.0.2"
authors = [
{ name="[Your Name]" },
]
description = "Example Software Development Kit (SDK) from Hands-On API Book for AI and Data Science"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
'pytest>=8.1',
'httpx>=0.27.0',
'pydantic>=2.7.0',
'backoff>=2.2.1,<2.3.0',
'pyarrow>=16.0,<17.0',
]
2 changes: 2 additions & 0 deletions sdk/src/swcpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .swc_client import SWCClient
from .swc_config import SWCConfig
1 change: 1 addition & 0 deletions sdk/src/swcpy/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .schemas import *
Loading

0 comments on commit defcceb

Please sign in to comment.