Skip to main content

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:

  1. define a flask blueprint
  2. create a restx.Namespace from defined model with crud_controller_factory function tools
  3. add this namespace to the blueprint
  4. 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


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.29.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

businessman-0.0.29-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file businessman-0.0.29.tar.gz.

File metadata

  • Download URL: businessman-0.0.29.tar.gz
  • Upload date:
  • Size: 5.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

Hashes for businessman-0.0.29.tar.gz
Algorithm Hash digest
SHA256 e4c370a06799d8d64cab06609a24248933245376d6fdd8a9999e28730141fd0e
MD5 aeeec5d0d0551abf6d4908a1ae4446ef
BLAKE2b-256 93c94c0c9ab6698cf8eb92edd9ca253e4b53d0f2eed5b735d412190d9f01dafa

See more details on using hashes here.

File details

Details for the file businessman-0.0.29-py3-none-any.whl.

File metadata

  • Download URL: businessman-0.0.29-py3-none-any.whl
  • Upload date:
  • Size: 8.4 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

Hashes for businessman-0.0.29-py3-none-any.whl
Algorithm Hash digest
SHA256 f4ff9a2efe13eb95940380f029c67239d9a222cb3fa0f363f3cf35ef1101c685
MD5 7bce1e645951f87ceebafc317db28249
BLAKE2b-256 c235da15178bc10ce9b7979ae705f2121f05602927e4174b43e1fe18ae0d32a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page