A small example package
Project description
Businessman Package
CRUD Business Logic with auto-generator controller for flask-restx.
example:
import what you need
from flask import Blueprint
from flask_mongoengine import Document
from mongoengine import StringField
from businessman import crud_controller_factory
MongoEngine model:
from flask_mongoengine import Document
from mongoengine import StringField
class SampleModel(Document):
meta = {"collection": "SampleModel"}
name = StringField()
code = StringField()
Restx Schema model:
from flask_restx import Api, fields
sample_schema = {
'name': fields.String(required=True, description=''),
'code': fields.String(required=True, description=''),
}
Blueprint and NameSpace:
blueprint = Blueprint('api', __name__)
api = Api(
blueprint,
title='Calendar API Service',
version='1.0',
description='A description',
# All API metadatas
)
ns1 = crud_controller_factory(model=SampleModel, schema_class=sample_schema)
api.add_namespace(ns1)
all of the above is for api.py
:
- define a flask blueprint
- create a
restx.Namespace
from defined model withcrud_controller_factory
function tools - add this namespace to the blueprint
- add the blueprint to the
flask.App
object
flask app.py
:
from flask import Flask
from flask_mongoengine import MongoEngine
from api import blueprint
app = Flask(__name__)
db = MongoEngine()
app.config.from_pyfile("config.py")
db.init_app(app)
app.register_blueprint(blueprint)
if __name__ == "__main__":
app.run(debug=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
businessman-0.0.25.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file businessman-0.0.25.tar.gz
.
File metadata
- Download URL: businessman-0.0.25.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e64798ab78f980831fada2e094a74c67466421e3361b3aeb539082e869098873 |
|
MD5 | 87f082d86b597271f55ada4420dd2f74 |
|
BLAKE2b-256 | 199d0ab5f5f93f8a3c12f82c5536cff1e0e0e7004c6b5850b76a5bba9fbfa367 |
File details
Details for the file businessman-0.0.25-py3-none-any.whl
.
File metadata
- Download URL: businessman-0.0.25-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b24b35529165528f732c3e98711f9eebd69d7835261e07ddff3179f719b4d763 |
|
MD5 | 5940ebc1004ddffdfea6e2ed1d8dd464 |
|
BLAKE2b-256 | eb22008db3b2e7438f9a5efa7feb8f20ce00bee3c8b0125fa6ade829d925567f |