songsopenapi / app.py
chriskasparaws's picture
Update app.py
070a1db verified
Raw History Blame Contribute Delete
839 Bytes
from fastapi import FastAPI
from pydantic import BaseModel
from typing import List
import uvicorn
app = FastAPI(title="Top Songs API", description="API to retrieve the top 10 songs played today", version="1.0.0")
class Song(BaseModel):
title: str
artist: str
album: str
class TopSongs(BaseModel):
songs: List[Song]
# Simulate a larger dataset of songs
all_songs = [
{"title": f"Song Title {i}", "artist": f"Artist Name {i}", "album": f"Album Name {i}"} for i in range(1, 101)
]
@app.get("/top-songs", response_model=List[Song], summary="Get the top 10 songs played today", response_description="Successful response")
async def read_top_songs():
# This example simply slices the first 10 songs to simulate "top songs"
return all_songs[:10]
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0")