A successful practice combining flask_restx with marshmallow
Project description
Flask-RESTX-marshmallow
Flask-RESTX-marshmallow is a powerful extension that seamlessly combines Flask, Flask-RESTX, and Marshmallow to provide a robust foundation for building RESTful APIs with automatic documentation and data validation.
✨ Features
- 🚀 Seamless Integration: Combines Flask-RESTX's API documentation with Marshmallow's powerful serialization
- 📋 Automatic Documentation: Generate interactive Swagger/OpenAPI documentation automatically
- 🔍 Data Validation: Built-in request/response validation using Marshmallow schemas
- 🎯 Type Safety: Full type hint support for better development experience
- 🔧 Easy Configuration: Minimal setup required to get started
- 📦 SQLAlchemy Integration: Works perfectly with Flask-SQLAlchemy
🔧 Requirements
- Python 3.12+
- Flask 3.1+
- Flask-RESTX 1.3+
- Marshmallow 4.0+
📦 Installation
Install the extension with pip:
pip install flask-restx-marshmallow
or with poetry:
poetry add flask-restx-marshmallow
or with uv
uv add flask-restx-marshmallow
🚀 Quick Start
Complete Example
For a comprehensive example with SQLAlchemy integration, see app.py. This example demonstrates:
- RESTful API endpoints with full CRUD operations
- Automatic request/response validation
- Interactive Swagger documentation
- Database integration with Flask-SQLAlchemy
- Error handling and status codes
The example application provides these endpoints:
| Endpoint | Method | Description |
|---|---|---|
/tasks/ |
GET | Query all tasks with optional filtering |
/tasks/ |
POST | Create a new task |
/tasks/<id> |
GET | Retrieve a specific task by ID |
/tasks/<id> |
PATCH | Update a task partially |
/tasks/<id> |
DELETE | Delete a task by ID |
🏃♂️ Running the Example
-
Clone the repository:
git clone https://github.com/1746104160/flask-restx-marshmallow.git && cd flask-restx-marshmallow -
Install dependencies:
poetry install --with devor
uv sync --dev -
Run the example application:
python app.pyor
flask run -
Visit
http://localhost:5000to explore the interactive API documentation.
📚 Documentation
Visit the interactive API documentation when running your application to explore all available endpoints and schemas. The documentation is automatically generated from your code and provides:
- Interactive API testing: Try out endpoints directly from the browser
- Schema visualization: See request/response models with examples
- Parameter documentation: Understand required and optional parameters
- Error responses: Learn about possible error scenarios
🧪 Testing
Run the test suite:
pytest
📄 License
This project is licensed under the MIT License.
🔗 Links
- GitHub Repository
- PyPI Package
- Flask Documentation
- Flask-RESTX Documentation
- Marshmallow Documentation
⭐ Star History
If you find this project useful, please consider giving it a star on GitHub!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_restx_marshmallow-0.2.0.tar.gz.
File metadata
- Download URL: flask_restx_marshmallow-0.2.0.tar.gz
- Upload date:
- Size: 502.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3510509ccbb98bf8ce936decd5627c12a581fb6b1800c77015ad6751499716d
|
|
| MD5 |
59c9b3a15a8e2326799cb7cc0b3b03d9
|
|
| BLAKE2b-256 |
3ed2484eba1885e7830cffaca6ff76a817f06ef63dae0cb87067a46adff7e15f
|
File details
Details for the file flask_restx_marshmallow-0.2.0-py3-none-any.whl.
File metadata
- Download URL: flask_restx_marshmallow-0.2.0-py3-none-any.whl
- Upload date:
- Size: 507.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a9760f8ca3e49ec1355fb829403e539bb46db7c747bdd87986c8849edf7cc6d
|
|
| MD5 |
a33cde2e5b97aadfeb8a5988bc19b9ee
|
|
| BLAKE2b-256 |
5339d9a946a64e6cf226358f2e4ca4fe3973261667e80df50eba411a3c42130d
|