https://github.com/speakeasy-api/flask-openapi-example
https://github.com/speakeasy-api/flask-openapi-example
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/speakeasy-api/flask-openapi-example
- Owner: speakeasy-api
- Created: 2024-11-08T08:10:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-08-04T20:55:43.000Z (11 months ago)
- Last Synced: 2025-09-29T06:44:00.010Z (9 months ago)
- Language: Python
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Speakeasy Flask OpenAPI Example
This is a simple Library API built with Flask, `flask-smorest`, and SQLAlchemy. It provides the endpoints used to manage books in a library, including creating, reading, updating, and deleting books. The API documentation is available via Swagger UI.
## Features
* Create, read, update, and delete books
* OpenAPI documentation served via Swagger UI
* SQLite database for data storage
## Prerequisites:
* Python 3.7+
* Flask
* `flask-smorest`
* Flask-SQLAlchemy
* `flask-marshmallow`
* PyYAML
## Installation
Clone the repository:
```bash
git clone https://github.com/speakeasy-api/openapi-flask-example.git
cd openapi-flask-example
```
Create and activate a virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
```
Install the dependencies:
```bash
pip install -r requirements.txt
```
## Running the application
Run the Flask application:
```bash
python app.py
```
The application will start on `http://127.0.0.1:5000`.
## API endpoints
* GET /books/ - List all books
* POST /books/ - Create a new book
* GET /books/ - Get a book by ID
* PUT /books/ - Update a book by ID
* DELETE /books/ - Delete a book by ID
* OpenAPI document is available to download at `http://127.0.0.1:5000/openapi.yaml`.
## Project structure
* `app.py` - The main application file
* `db.py` - Database initialization
* `models.py` - Database models
* `resources.py` - API resources and blueprints
* `schemas.py` - Marshmallow schemas