Skip to main content

Adds Django REST Framework inspired viewsets to Flask.

Project description

Flask-Viewsets

Flask-Viewsets is a Python package that provides a ViewSet class, inheriting from Flask's View, inspired by Django REST Framework's ViewSet. This package aims to streamline the development of RESTful APIs in Flask by offering a simple and flexible class-based view structure for mapping HTTP methods to defined actions on a per route basis.

Features

  • Provides an easy-to-use class-based view to manage HTTP methods.
  • Supports all HTTP methods (GET, POST, PUT, PATCH, DELETE, ...).
  • Extensible and customizable for various use cases.

Installation

You can install Flask-Viewsets using pip:

pip install Flask-Viewsets

Usage

To use the ViewSet class, import it in your Flask application, define a viewset class by inheriting ViewSet, and implement the desired HTTP methods. Here’s a simple example:

# views.py
from flask_viewsets import ViewSet

class ExampleViewSet(ViewSet):
    def hello(self):
        return "Hello, world!"

    def echo(self, message: str):
        return message
# app.py
from flask import Flask

from . import views

app = Flask(__name__)
app.add_url_rule('/hello', view_func=views.ExampleViewSet.as_view({
    "get": "hello"
}))
app.add_url_rule('/echo/<string:message>', view_func=views.ExampleViewSet.as_view({
    "get": "echo"
}))

if __name__ == "__main__":
    app.run(debug=True)

Requirements

  • Python ^3.12
  • Flask ^3.0.3

Contributing

Contributions are welcome! Please feel free to submit a pull request, file an issue, or suggest improvements.

License

This project is licensed under the GNU Affero General Public License. See the LICENSE.md file for details.

Enjoy using Flask-Viewsets? Give it a star and help make Flask development easier!

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_viewsets-0.1.3.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

flask_viewsets-0.1.3-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file flask_viewsets-0.1.3.tar.gz.

File metadata

  • Download URL: flask_viewsets-0.1.3.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for flask_viewsets-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b8cf0c1adc13811053d1927d83c9ae99529259a1e5d7dd04b764930b84317cb6
MD5 79cd51d06a3dd9e2a8fe039e1dad72bc
BLAKE2b-256 8456adf14ad334adaf0984482459e6801d2a59d8d8951c7e94fa033c1c8f91f5

See more details on using hashes here.

File details

Details for the file flask_viewsets-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: flask_viewsets-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for flask_viewsets-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 92947fc085b075b1184f5c9323d3dce0f2cd75a5c4f1743a4e4834e3948cf098
MD5 caac9c37447be31341f8153ff1a13f03
BLAKE2b-256 90d52d65a94943c9ae3a1ca4250b4d2e46f67e23ce5dea5cb4c74f48380e2b3a

See more details on using hashes here.

Supported by

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