معرفی شرکت ها


flask-jsonapi-trivial-0.2.5


Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر
Card image cap
تبلیغات ما

مشتریان به طور فزاینده ای آنلاین هستند. تبلیغات می تواند به آنها کمک کند تا کسب و کار شما را پیدا کنند.

مشاهده بیشتر

توضیحات

Provides Flask with *very basic* JSONAPI.org compliance
ویژگی مقدار
سیستم عامل -
نام فایل flask-jsonapi-trivial-0.2.5
نام flask-jsonapi-trivial
نسخه کتابخانه 0.2.5
نگهدارنده []
ایمیل نگهدارنده []
نویسنده austinjp
ایمیل نویسنده austin.plunkett+pypi@gmail.com
آدرس صفحه اصلی http://github.com/subsect/flask_jsonapi_trivial/
آدرس اینترنتی https://pypi.org/project/flask-jsonapi-trivial/
مجوز CC BY-NC-SA 4.0
# Flask JSONAPI Trivial Provides Flask with *very basic* compliance with JSONAPI.org. It enables easy construction of APIs that return JSON. Statuses or exceptions generated by the following modules are automatically transformed to JSONAPI while keeping the correct HTTP headers: - http.HTTPStatus - Jose (for JWT exceptions) - Werkzeug (for Flask itself) Note, all exceptions raised by Jose (for JWT exceptions) are converted to Werkzeug Unauthorized 401 exceptions. Extra information about the JWT error is added to the returned JSON. ## Example ```python from flask import Flask, abort from flask_jsonapi_trivial import jsonapi, JsonApiModel from flask_sqlalchemy import SQLAlchemy from datetime import datetime from werkzeug import exceptions import json db = SQLAlchemy() app = Flask(__name__) # Add the @jsonapi decorator and return a # status or exception, plus optional JSON # object. Only keys 'meta', 'included', # 'data', and 'links' are taken from this # JSON object. Anything else is ignored. @app.route("/") @jsonapi def hello_world(): return HTTPStatus.OK, { "meta": "Hello, world!" } # Get Flask to return JSON for exceptions. # Exceptions raised Werkzeug and Jose # are supported, as well as all HTTPStatus types. @app.errorhandler(jose.exceptions.JWTError) @app.errorhandler(exceptions.NotImplemented) def custom_error_handler(e): return jsonapi_response(e) # Standard errors can simply be raised, the # custom error handler catches them. @app.route('/raise') def raise_error(): raise exceptions.NotImplemented # Errors can simply be returned as well: @app.route('/show_error') @jsonapi def show_error(): return exceptions.ImATeapot # Flask abort() will return JSON if the error # handler has been registered, provided it is # called with an appropriate numerical code. @app.route('/abort') @jsonapi def flask_abort(): abort(exceptions.NotImplemented.code) # flask_jsonapi_trivial allows standard database # models to easily expose a jsonapi() method # simply by extending JsonApiModel class. # The class needs to implement a json() # method which needs to return a dict JSON # representation. Appropriate formatting is # up to you -- see below for an example. class MyModel(db.Model, JsonApiModel): __tablename__ = 'my_table' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String) last_seen = db.Column(db.DateTime, default=datetime.utcnow) def __init__(self): self.id = None self.name = "Default Name" self.last_seen = datetime.utcnow() def json(self): if self.id is not None: self.id = str(self.id) if self.name is not None: self.name = str(self.name) return { "id": self.id, "name": self.name, "last_seen": json.loads(json.dumps(self.last_seen,default=str)) } # Then it's simple to return the JSON representation # of the model. Correct headers etc are taken care of. @app.route('/show_model') @jsonapi def show_model(): model = MyModel() model.id = 1 model.name = "Whom So Ever" return HTTPStatus.OK, model.jsonapi() # The method jsonapi_limited() strips all detail # from the model, leaving the keys intact. Any "id" # field is removed unless specified. @app.route('/show_limited_model') @jsonapi def show_limited_model(): model = MyModel() model.id = 999 model.name = "Limited Model" return HTTPStatus.OK, model.jsonapi_limited(show_id=True) ```


نیازمندی

مقدار نام
>=2.9.2 cryptography
>=1.0.2 Flask
>=3.1.0 python-jose[cryptography]
>=0.15.3 Werkzeug


زبان مورد نیاز

مقدار نام
~=3.6 Python


نحوه نصب


نصب پکیج whl flask-jsonapi-trivial-0.2.5:

    pip install flask-jsonapi-trivial-0.2.5.whl


نصب پکیج tar.gz flask-jsonapi-trivial-0.2.5:

    pip install flask-jsonapi-trivial-0.2.5.tar.gz