{"id":15024955,"url":"https://github.com/patrickmccallum/flask-prism","last_synced_at":"2026-02-19T05:31:42.700Z","repository":{"id":57430614,"uuid":"43667541","full_name":"patrickmccallum/flask-prism","owner":"patrickmccallum","description":"PRISM is the easy way to build manageable APIs for Flask","archived":false,"fork":false,"pushed_at":"2020-10-15T11:52:08.000Z","size":57,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-26T10:28:22.411Z","etag":null,"topics":["flask","flask-api","flask-prism","json"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrickmccallum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-05T05:54:09.000Z","updated_at":"2023-06-20T04:42:16.000Z","dependencies_parsed_at":"2022-08-27T22:30:28.366Z","dependency_job_id":null,"html_url":"https://github.com/patrickmccallum/flask-prism","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/patrickmccallum/flask-prism","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickmccallum%2Fflask-prism","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickmccallum%2Fflask-prism/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickmccallum%2Fflask-prism/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickmccallum%2Fflask-prism/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickmccallum","download_url":"https://codeload.github.com/patrickmccallum/flask-prism/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickmccallum%2Fflask-prism/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29604552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T05:11:50.834Z","status":"ssl_error","status_checked_at":"2026-02-19T05:11:38.921Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","flask-api","flask-prism","json"],"created_at":"2024-09-24T20:01:16.360Z","updated_at":"2026-02-19T05:31:42.685Z","avatar_url":"https://github.com/patrickmccallum.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\r\n\r\n![alt text](http://flask-prism.readthedocs.io/en/latest/_static/prism_small.png \"Flask-PRISM\")\r\n\r\nPRISM is a simple way to manage your Flask APIs, providing consistent models, version management, access control, and more while leaving you in full control of your code. It's even super easy to use.\r\n\r\nCheck out this Flask-SQLAlchemy model that's using PRISM:\r\n\r\n```python\r\nfrom prism import p\r\n\r\nclass User(db.Model):\r\n\r\n    # Define table name\r\n    __tablename__ = 'users'\r\n\r\n    # Primary key, user ID\r\n    user_id = db.Column(db.Integer, primary_key=True, autoincrement=True, index=True)\r\n\r\n    # First name\r\n    first_name = db.Column(db.String(255))\r\n\r\n    # Email\r\n    email = db.Column(db.String(255))\r\n\r\n    # Password\r\n    password = db.Column(db.String(255))\r\n\r\n    @p.api_representation()\r\n    def as_data(self):\r\n        return {\r\n            'id': self.user_id,\r\n            'email': self.email,\r\n            'first_name': self.first_name\r\n        }\r\n```\r\n\r\nNow in our API let's set up a route to return all users. All we do is return our Flask-SQLAlchemy models through a PRISM **Refract**\r\n\r\n```python\r\nfrom flask import Blueprint\r\nfrom models import User\r\nfrom flask.ext.prism import Refract\r\n\r\nbp = Blueprint('api', __name__, url_prefix=\"/api\")\r\n\r\n@bp.route('/users')\r\ndef api_users_get():\r\n    # Return with as_list=True, this forces the JSON to be an array even if there's only one result.\r\n    return Refract(User.query.all(), as_list=True)\r\n\r\n```\r\n\r\nWhich returns a nice clean and easy output\r\n```json\r\n[\r\n    {\r\n        \"user_id\": 1,\r\n        \"email\": \"some_email@internet.co\",\r\n        \"first_name\": \"Roger\"\r\n    },\r\n    {\r\n        \"user_id\": 2,\r\n        \"email\": \"just@use.slack\",\r\n        \"first_name\": \"Jennifer\"\r\n    }\r\n]\r\n```\r\n\r\n\r\nFeatures\r\n--------\r\n\r\n- Easily manage your JSON models from a predictable location\r\n- Insert permission based rules into your JSON output\r\n- Models and permission checks can be easily versioned by passing a ``version=INTEGER`` parameter\r\n\r\n\r\n\r\n\r\n### Installation\r\n\r\nYou can grab Flask-PRISM using pip (our Pypi page is [over here](https://pypi.python.org/pypi?name=Flask-PRISM\u0026:action=display))\r\n\r\n```sh\r\n$ pip install Flask-PRISM\r\n```\r\n\r\nInstantiate our **Prism** object in a separate file, in this example it's in ``prism.py``\r\n```python\r\nfrom flask.ext.prism import Prism\r\n\r\np = Prism()\r\n```\r\n\r\nAnd finally, call ``init_app()`` during setup.\r\n```python\r\nfrom flask import Flask\r\nfrom flask.ext.prism import Refract\r\nfrom prism import p\r\n\r\nfrom models import User\r\n\r\n# Setup flask like we normally do\r\napp = Flask(__name__)\r\n\r\n# Setup PRISM to see Flask\r\np.init_app(app)\r\n\r\n@app.route('/api/users/\u003cint:user_id\u003e')\r\ndef api_user_get(user_id):\r\n    return Refract(User.query.get(user_id))\r\n\r\nif __name__ == '__main__':\r\n    app.run()\r\n```\r\n\r\nWhich returns a nice clean and easy output\r\n```json\r\n{\r\n    \"user_id\": 1,\r\n    \"email\": \"some_email@internet.co\",\r\n    \"first_name\": \"Roger\"\r\n}\r\n```\r\n\r\n\r\n\r\n\r\n### Documentation\r\n\r\nYou can find all the Flask-PRISM documentation at [flask-prism.readthedocs.org](https://flask-prism.readthedocs.org/)\r\n\r\n\r\n\r\n\r\n### Development\r\n\r\nWant to contribute? Awesome!\r\nIf you've made a change you think will help other PRISM users, just open a pull request or raise an issue on GitHub.\r\n\r\nIf you're not already there, it's over at \u003chttps://github.com/patrickmccallum/flask-prism\u003e\r\n\r\nDidn't read the docs? My Twitter is [@patsnacks](https://twitter.com/patsnacks).\r\n\r\n\r\n### Changelog\r\n##### 0.4.0 BREAKING CHANGES\r\n- Renamed ReturnableResponse to Refract, shorter, makes more sense given the context\r\n- Fixed new line issue in response mapping\r\n\r\n##### 0.3.2\r\n- Fixed an issue with the as_list parameter that could cause it to be ignored in certain cases\r\n- Tweaked the docs\r\n\r\n##### 0.3.1\r\n- Fixed issue that would cause deployments to fail with Apache's mod_wsgi, and subsequently AWS Elastic Beanstalk\r\n\r\n##### 0.3.0\r\n- PRISM representations can now contain other objects with representations! They'll be auto converted on the way out\r\n- Removed stray print statements used for debugging\r\n\r\n##### 0.2.2\r\n- Added documentation\r\n\r\n##### 0.2.1\r\n - Initial release\r\n\r\n\r\n### License\r\n\r\n\r\nFlask-PRISM is distributed under the MIT license. See the LICENSE file included in this project for more.\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickmccallum%2Fflask-prism","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickmccallum%2Fflask-prism","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickmccallum%2Fflask-prism/lists"}