9 examples of 'flask minimal app' in Python

Every line of 'flask minimal app' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
13def create_app(debug=False):
14 app = Flask(__name__)
15 app.debug = debug
16
17 # Make trailing slashes in routes redundant.
18 app.url_map.strict_slashes = False
19 app.url_map.converters['array'] = ListConverter
20
21 return app
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

6@pytest.fixture
7def app():
8 app = Flask(__name__)
9 Debug(app)
10 app.config['DEBUG'] = True
11 app.config['TESTING'] = True
12 app.config['FLASK_DEBUG_DISABLE_STRICT'] = True
13
14 assert app.debug
15 assert app.testing
16 return app
7def create_app():
8 app = Flask(__name__)
9 metrics.init_app(app)
10 return app
15def get_app():
16 global APP
17
18 if APP is None:
19 app = Flask(__name__)
20 app.config.from_object('puppetboard.default_settings')
21 app.config.from_envvar('PUPPETBOARD_SETTINGS', silent=True)
22 app.secret_key = app.config['SECRET_KEY']
23
24 numeric_level = getattr(logging, app.config['LOGLEVEL'].upper(), None)
25 if not isinstance(numeric_level, int):
26 raise ValueError('Invalid log level: %s' % app.config['LOGLEVEL'])
27
28 app.jinja_env.filters['jsonprint'] = jsonprint
29 app.jinja_env.filters['prettyprint'] = prettyprint
30 app.jinja_env.globals['url_for_field'] = url_for_field
31 app.jinja_env.globals['url_static_offline'] = url_static_offline
32 APP = app
33
34 return APP
24def create_app(config_filename=None, db_url=database_file):
25 app = Flask(__name__)
26 if config_filename:
27 app.config.from_pyfile(config_filename)
28 init_extensions(app, db_url)
29 register_blueprints(app)
30 return app
18def create_app():
19 app = Flask(__name__)
20 models.init_app(app)
21 routes.init_app(app)
22 services.init_app(app)
23 return app
11def create_app(environment):
12 app = Flask(__name__)
13 app.config.from_object(config[environment])
14
15 db.init_app(app)
16 migrate.init_app(app, db=db)
17
18 from .auth.models import User
19
20 def authenticate(email, password):
21 data = request.json
22 user = User.query.filter_by(email=data['email']).first()
23 if user is not None and user.verify_password(data['password']):
24 return user
25
26 def identity(payload):
27 user_id = payload['identity']
28 return User.query.filter_by(id=user_id).first()
29
30 jwt = JWT(app, authenticate, identity)
31
32
33 from .auth import auth as auth_blueprint
34 app.register_blueprint(auth_blueprint, url_prefix='/auth')
35
36 from .todo import todo as todo_blueprint
37 app.register_blueprint(todo_blueprint)
38
39 return app
29def create_app():
30
31 app = Flask("runner_service")
32
33 # Apply any local configuration to the flask instance
34 app.config.from_object(configuration.settings)
35
36 api = Api(app)
37
38 api.add_resource(ListPlaybooks, "/api/v1/playbooks")
39 api.add_resource(StartPlaybook, "/api/v1/playbooks/<playbook_name>")
40 api.add_resource(StartTaggedPlaybook, "/api/v1/playbooks/<playbook_name>/tags/<tags>") # noqa: E501
41 api.add_resource(PlaybookState, "/api/v1/playbooks/<play_uuid>")
42
43 api.add_resource(ListEvents, "/api/v1/jobs/<play_uuid>/events")
44 api.add_resource(GetEvent, "/api/v1/jobs/<play_uuid>/events/<event_uuid>")
45
46 api.add_resource(ListGroups, "/api/v1/groups")
47 api.add_resource(ManageGroups, "/api/v1/groups/<group_name>")
48
49 api.add_resource(Hosts, "/api/v1/hosts")
50 api.add_resource(HostDetails, "/api/v1/hosts/<host_name>")
51 api.add_resource(HostMgmt, "/api/v1/hosts/<host_name>/groups/<group_name>")
52
53 api.add_resource(HostVars, "/api/v1/hostvars/<host_name>/groups/<group_name>") # noqa: E501
54 api.add_resource(GroupVars, "/api/v1/groupvars/<group_name>") # noqa: E501
55
56 api.add_resource(API, "/api")
57 api.add_resource(PrometheusMetrics, "/metrics")
58
59 # push the app object into the API class, so it can walk the
60 # API endpoints.
61 API.app = app
62
63 return app
29def create_app(config_filename=None):
30 app = Flask("demo_app")
31 app.config.update(SQLALCHEMY_DATABASE_URI="sqlite://")
32 db.init_app(app)
33 with app.app_context():
34 db.create_all()
35 create_api(app)
36 return app

Related snippets