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.
- Create, read, update, and delete books
- OpenAPI documentation served via Swagger UI
- SQLite database for data storage
- Python 3.7+
- Flask
flask-smorest
- Flask-SQLAlchemy
flask-marshmallow
- PyYAML
Clone the repository:
git clone https://github.com/speakeasy-api/openapi-flask-example.git
cd openapi-flask-example
Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
Install the dependencies:
pip install -r requirements.txt
Run the Flask application:
python app.py
The application will start on http://127.0.0.1:5000
.
- GET /books/ - List all books
- POST /books/ - Create a new book
- GET /books/int:book_id - Get a book by ID
- PUT /books/int:book_id - Update a book by ID
- DELETE /books/int:book_id - Delete a book by ID
- OpenAPI document is available to download at
http://127.0.0.1:5000/openapi.yaml
.
app.py
- The main application filedb.py
- Database initializationmodels.py
- Database modelsresources.py
- API resources and blueprintsschemas.py
- Marshmallow schemas