Skip to main content

Flask extension to create REST web api according to JSONAPI 1.0 specification with Flask, Marshmallow and data provider of your choice (SQLAlchemy, MongoDB, ...)

Project description

flask-rest-jsonapi-next

PyPi Status license tests Documentation Status python_versions

This is a fork of miLibris/flask-rest-jsonapi project.

flask-rest-jsonapi-next is a flask extension for building REST APIs around a strong specification JSON:API 1.0.

Documentation: http://flask-rest-jsonapi-next.readthedocs.io/en/latest/

Install

pip install flask-rest-jsonapi-next

A minimal API

from flask import Flask
from flask_rest_jsonapi_next import Api, ResourceDetail, ResourceList
from flask_sqlalchemy import SQLAlchemy
from marshmallow_jsonapi.flask import Schema
from marshmallow_jsonapi import fields

# Create the Flask application and the Flask-SQLAlchemy object.
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)

# Create model
class Person(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)

# Create the database.
db.create_all()

# Create schema
class PersonSchema(Schema):
    class Meta:
        type_ = 'person'
        self_view = 'person_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'person_list'

    id = fields.Integer(as_string=True, dump_only=True)
    name = fields.Str()

# Create resource managers
class PersonList(ResourceList):
    schema = PersonSchema
    data_layer = {'session': db.session,
                    'model': Person}

class PersonDetail(ResourceDetail):
    schema = PersonSchema
    data_layer = {'session': db.session,
                    'model': Person}

# Create the API object
api = Api(app)
api.route(PersonList, 'person_list', '/persons')
api.route(PersonDetail, 'person_detail', '/persons/<int:id>')

# Start the flask loop
if __name__ == '__main__':
    app.run()

This example provides the following API structure:

URL method endpoint Usage
/persons GET person_list Get a collection of persons
/persons POST person_list Create a person
/persons/<int:person_id> GET person_detail Get person details
/persons/<int:person_id> PATCH person_detail Update a person
/persons/<int:person_id> DELETE person_detail Delete a person

Thanks

Flask, marshmallow, marshmallow_jsonapi, sqlalchemy, Flask-RESTful and Flask-Restless are awesome projects. These libraries gave me inspiration to create flask-rest-jsonapi-next, so huge thanks to authors and contributors.

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_rest_jsonapi_next-0.47.3.tar.gz (33.2 kB view details)

Uploaded Source

Built Distribution

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

flask_rest_jsonapi_next-0.47.3-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file flask_rest_jsonapi_next-0.47.3.tar.gz.

File metadata

  • Download URL: flask_rest_jsonapi_next-0.47.3.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flask_rest_jsonapi_next-0.47.3.tar.gz
Algorithm Hash digest
SHA256 9adbbc39a5bb994f7a0ec6baa2daecf01e728dc844c111e54f2b0bd13de4a902
MD5 3b5c8cdc51d58dc68124e089a75e4edc
BLAKE2b-256 01e72a8c5a7ec98a7820d2db2d63d92584d767c8a127fae2ef23072853009e5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_rest_jsonapi_next-0.47.3.tar.gz:

Publisher: pypi-publish.yaml on tadams42/flask-rest-jsonapi-next

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_rest_jsonapi_next-0.47.3-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_rest_jsonapi_next-0.47.3-py3-none-any.whl
Algorithm Hash digest
SHA256 84339cf848da70f35cfd86dede6caf667b52cf99cc088facb4cb35592848da60
MD5 a078b32e9f6a7661b5a9bce704d4623c
BLAKE2b-256 3a3eaa84d222be05f9d692efe9b63d3192bc75a5e4d03529904bf08c7d7f81e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_rest_jsonapi_next-0.47.3-py3-none-any.whl:

Publisher: pypi-publish.yaml on tadams42/flask-rest-jsonapi-next

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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