Flask Smorest CRUD
Why repeat yourself?
This library aims to tie together Flask-SQLAlchemy and Flask-Smorest to implement a sane default but easily customizable CRUD API based on SQLAlchemy models inside of Flask.
Quickstart
In create_app():
from smorest_crud import CRUD
from flask_jwt_extended import JWTManager, get_current_user
app = Flask()
JWTManager(app)
CRUD(app)
app.config.update(
CRUD_GET_USER=get_current_user,
CRUD_ACCESS_CHECKS_ENABLED=True,
SECRET_KEY="wnt2die",
)
CRUD View:
from flask_smorest import Blueprint
from smorest_crud import ResourceView, CollectionView
pet_blp = Blueprint("pets", "pets", url_prefix="/pet")
@pet_blp.route("")
class PetCollection(CollectionView):
model = Pet
prefetch = [Pet.human, (Pet.human, Human.cars)] # joinedload
access_checks_enabled = False
create_enabled = True
list_enabled = True
@pet_blp.response(PetSchema(many=True))
def get(self):
"""List pets."""
query = super().get()
return query.filter_by(name='mischa')
@pet_blp.arguments(PetSchema)
@pet_blp.response(PetSchema(many=True))
def post(self, args):
"""Create a pet."""
return super().post(args)
@pet_blp.route("/<int:pk>")
class PetResource(ResourceView):
model = Pet
access_checks_enabled = True
get_enabled = True
update_enabled = True
delete_enabled = True
@pet_blp.response(PetSchema)
def get(self, pk):
return super().get(pk)
@pet_blp.arguments(PetSchema)
@pet_blp.response(PetSchema)
def patch(self, args, pk):
return super().patch(args, pk)
@pet_blp.response(PetSchema)
def delete(self, pk):
return super().delete(pk)
Who is this for?
This library is only useful if your application uses:
Where to look?
Look at smorest_crud/test/app.py
Feedback and comments welcome. What would you like to see? Open an issue or a PR with your thoughts.
Metadata
Release files for smorest-crud 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| smorest-crud-0.0.7.tar.gz | 6.6 kB | Without provenance | Details for smorest-crud-0.0.7.tar.gz |
Release files / smorest-crud-0.0.7.tar.gz
| Download URL | smorest-crud-0.0.7.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7bf42236f085e0934dd70b3c6c1a2de5179260988a8981bfbd0c548fc2412f0
|
|
BLAKE2b-256 checksum How to use checksums |
29002cc9a795f6f5f492cf15aeedaae2391c30eaf241c5aa156047a103e23c03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.2
|
Security for smorest-crud 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.