Skip to main content

A successful practice combining flask_restx with marshmallow

Project description

Flask-RESTX-marshmallow

PyPI version Python version License

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

  1. Clone the repository:

    git clone https://github.com/1746104160/flask-restx-marshmallow.git && cd flask-restx-marshmallow
    
  2. Install dependencies:

    poetry install --with dev
    

    or

    uv sync --dev
    
  3. Run the example application:

    python app.py
    

    or

    flask run
    
  4. Visit http://localhost:5000 to 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

⭐ Star History

If you find this project useful, please consider giving it a star on GitHub!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_restx_marshmallow-0.2.0.tar.gz (502.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_restx_marshmallow-0.2.0-py3-none-any.whl (507.9 kB view details)

Uploaded Python 3

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

Hashes for flask_restx_marshmallow-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c3510509ccbb98bf8ce936decd5627c12a581fb6b1800c77015ad6751499716d
MD5 59c9b3a15a8e2326799cb7cc0b3b03d9
BLAKE2b-256 3ed2484eba1885e7830cffaca6ff76a817f06ef63dae0cb87067a46adff7e15f

See more details on using hashes here.

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

Hashes for flask_restx_marshmallow-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a9760f8ca3e49ec1355fb829403e539bb46db7c747bdd87986c8849edf7cc6d
MD5 a33cde2e5b97aadfeb8a5988bc19b9ee
BLAKE2b-256 5339d9a946a64e6cf226358f2e4ca4fe3973261667e80df50eba411a3c42130d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page