{"id":19686344,"url":"https://github.com/closeio/flask-restutils","last_synced_at":"2025-07-06T00:09:21.315Z","repository":{"id":49111190,"uuid":"82874938","full_name":"closeio/flask-restutils","owner":"closeio","description":"Helpers for REST APIs with Flask / SQLAlchemy / flask-restful","archived":false,"fork":false,"pushed_at":"2021-06-28T15:58:27.000Z","size":23,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-29T06:33:12.217Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/closeio.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":"2017-02-23T02:26:12.000Z","updated_at":"2021-06-28T15:58:30.000Z","dependencies_parsed_at":"2022-09-24T02:42:51.418Z","dependency_job_id":null,"html_url":"https://github.com/closeio/flask-restutils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/closeio/flask-restutils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/closeio%2Fflask-restutils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/closeio%2Fflask-restutils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/closeio%2Fflask-restutils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/closeio%2Fflask-restutils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/closeio","download_url":"https://codeload.github.com/closeio/flask-restutils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/closeio%2Fflask-restutils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261374413,"owners_count":23148976,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-11T18:27:36.589Z","updated_at":"2025-06-22T22:05:22.113Z","avatar_url":"https://github.com/closeio.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flask-restutils\n\n[![CircleCI](https://circleci.com/gh/closeio/flask-restutils.svg?style=svg)](https://circleci.com/gh/closeio/flask-restutils)\n\nHelpers for building REST APIs with Flask / SQLAlchemy / flask-restful.\n\n## Management commands (`flask_restutils.commands`)\n\nTo use the management commands, you need both `flask-script` and `flask-sqlalchemy`. The provided commands are:\n\n* `sqlcreate`: Creates all SQL tables\n* `sqlreset`: Drops and recreates all SQL tables\n\nAll management can be added using the `add_sql_commands` helper as follows:\n\n```\nfrom flask_restutils.commands import add_sql_commands\nadd_sql_commands(manager)\n```\n\n## Helpers (`flask_restutils.helpers`)\n\n* `get_db()`: Returns the SQLAlchemy database object. Requires `flask-sqlalchemy`.\n* `request_json()`: Returns the (unserialized) JSON data from the request body, or raises a 400 error in case of an error or invalid content type. Requires Flask 0.11.\n\n## Models (`flask_restutils.models`)\n\n* `BaseModelMixin`: SQLAlchemy declarative model mixin that adds `date_created`/`date_updated` columns, a `Model.get()` method (shorthand for `Model.query.get(pk)`, and can be overridden in subclasses), and a nicer `__repr__`.\n* `VersionMixin`: SQLAlchemy declarative model mixin that adds a version counter. It uses optimistic locking and raises `sqlalchemy.orm.exc.StaleDataError` when two concurrent transactions are trying to modify the model (see http://docs.sqlalchemy.org/en/latest/orm/versioning.html).\n\n## Random PK (`flask_restutils.random_pk`)\n\nRequires the `zbase62` module (https://github.com/closeio/zbase62/tree/python3-fixes).\n\nProvides `RandomPKMixin`, a SQLAlchemy declarative model mixin that adds an `id` primary key column that internally uses a random UUID4, and publicly uses an ID comprised of a prefix and a Zbase62 representation of the UUID, e.g. `book_5ASpCqHpi5yyQRY0PjuUIR`. Example usage:\n\n```\nclass Book(RandomPKMixin, sql.Model):\n    __tablename__ = 'book'\n```\n\nThe ID prefix by default consists of the first 4 letters of the model and can be customized as follows:\n\n```\nclass Author(RandomPKMixin, sql.Model):\n    __tablename__ = 'author'\n    class Meta:\n        id_prefix = 'author'\n```\n\n## Resources (`flask_restutils.resources`)\n\nRequires `flask-restful` and `cleancat`.\n\nProvides `ModelBasedResource`, a `flask_restful.Resource` subclass that provides CRUD functionality for SQLAlchemy models with cleancat schema validation.\n\nExample resource:\n\n```\nfrom flask_restutils.resources import ModelBasedResource\n\nfrom . import models, schemas\n\nclass BookResource(ModelBasedResource):\n    class Meta:\n        pk_field = 'id'\n        model = models.Book\n        schema = schemas.Book\n```\n\nExample schema:\n\n```\nclass Book(Schema):\n    id = String(read_only=True)\n    author = String(mutable=False)\n    title = String()\n```\n\nExample view:\n\n```\nfrom flask_restful import Api\nfrom book.resources import BookResource\n\napi = Api(app)\napi.add_resource(BookResource, '/book/',\n                               '/book/\u003cpk\u003e/')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloseio%2Fflask-restutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloseio%2Fflask-restutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloseio%2Fflask-restutils/lists"}