0% found this document useful (0 votes)
22 views7 pages

2

Uploaded by

Bruna Oliveira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

2

Uploaded by

Bruna Oliveira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
CHAPTER 7 — MONITORING FLASK APPLICATIONS Flask-WhooshAlchemy Whoosh is a fast, search engine library built in Python and is highly flexible and supports complex data searching based on free-form or structured text. Flask-WhooshAlchemy is a Flask extension to integrate the Whoosh search engine library with SQLAlchemy in Flask. It’s pretty straightforward to integrate and get your full text search up without any third-party application unlike pyelasticsearch. You can learn more about it at https: //pythonhosted.org/Flask-WhooshAlchemy/ We used Flask mail for verifying user emails. Here is a list of other libraries you can use for efficient email integration in your application. Flask-SendGrid Flask-SendGrid is a Flask extension to simplify sending email using sendgrid which is a renowned email service; you can sign up for SendGrid at https: //sendgrid. com/; they provide a free subscription which includes 40,000 emails for first 30 days and 100/day forever. You can check out Flask SendGrid at https: //github. com/frankv/flask-sendgrid which makes sending email a piece of cake. AWS SNS Using Boto3 Boto3 is an AWS SDK for Python, and you can use AWS’ SNS (Simple Notification Service) to send email and text message using Boto. Here is a guide to sending email using Python with Boto https: //docs.aws. amazon. com/ses/latest/DeveloperGuide/send-using-sdk-python. html. You'll need an active AWS account for this and Boto installed from https: //boto3.readthedocs. io/en/latest/guide/quickstart. html#installation. 193 CHAPTER 7 MONITORING FLASK APPLICATIONS. File Storage File storage is an important aspect of an application; we stored user avatars in an application server file system which is not a good approach for production applications, and in such cases you’d like to store and access your files using afile storage service. Here are a handful of suggestions for the same. AWS $3 Using Boto3 You can leverage Boto3 to manage your files on Amazon AWS S3, which is a powerful file management system. This guide will provide you with everything you need to manage your files using Flask https : //boto3 . amazonaws . com/v1/documentation/api/latest/reference/services/ s3.html Alibaba Cloud OSS Alibaba Cloud provides a sophisticated file storage platform called Object Storage Service; you can use their Python SDK from https: //github. com/aliyun/aliyun-oss-python-sdk and easily setup file management using their OSS guide which is available at https: //help.aliyun.com/ document_detail/32026. html Conclusion This marks the end of this chapter and the book. There is a lot more to explore in optimizing and upgrading your application, but this will serve as the right base to grow from; if you have issues in integrating any of the mentioned services, check out their official docs, reach out to support, or reach out on Stack Overflow to solve them. You can also use this link to ask or read queries regarding Flask https : //stackoverflow. com/ search?q=flask. 194 Index A,B Alibaba Cloud ECS Console, 161 Amazon AWS $3, 194 Assertion methods, 140 c Caching, 13 Create, Read, Update, and Delete (CRUD), 4 CRUD application adds global responses, 71, 72 API documentation building blocks, 115 OAS see (OpenAPI Specification (OAS)) application structure, 64 author route blueprint registration, 78 blueprints, 60 create authors model, 65, 66 create books model, 64 create __init_.py, 62 create responses.py inside api/utils, 67 creating POST book endpoint, 79 db.init_app function, 70 © Kunal Relan 2019 DELETE endpoints, 77, 84, 85 email verification create_user() method, 104, 105 flask-mail library installation, 103 GET endpoint, 102 login method, 101 token.py, 100 URLSafeTimedSerializer, 101 User class code, 98, 99 User email verification, 108 User login after verification, 108 User login without verification, 107 user signup API, 106, 107 users.py in models, 98 fetch author ID, 76, 80 file upload add avatar field, 109, 111 avatar endpoint with invalid file type, 114 avatar field endpoint, 112 fetch avatar endpoint, 113 GET author endpoint, 81, 82 GET authors route, 75 GET books endpoint, 86 K. Relan, Building REST APIs with Flask, https:/ /doi.org/10.1007/978-1-4842-5022-8 INDEX CRUD application (cont.) HTTP responses, 68 import create_app, 61 PATCH endpoint, 83 POST author route, 73 POST authors endpoint, 74 PUT author endpoint, 82 user authentication create POST user route, 91 create schema, 88, 89 Flask-JWT-Extended, 89 login endpoint, 94 POST author route, 95, 96 POST users endpoint, 93 user signup endpoint, 93 Database modelling creating author database, 34 db.create_all(), 34 DELETE author by ID, 43-45 GET all authors, 39 GET author by ID endpoint, 40 GET/authors response, 36, 37 POST/authors endpoint, 38 PUT endpoint, 41, 42 RESTful CRUD APIs, 33 Flask-SQLAlchemy, 30-32 MongoEngine application create db instance, 47, 48 create PUT endpoint, 54, 55 196 CRUD application, 56-58 delete endpoint, 55 GET endpoint, 48, 50 installation, 47 JSON data, 51 requesting POST /authors, 51,52 MySQL vs MongoDB, 29 NoSQL databases, 28 SQLAlchemy, creating author database, 34 SQL databases, 28 db.init_app function, 70 Deploying applications Alibaba Cloud ECS GitHub repo, 162 Gunicorn, 167-169, 171 Nginx, 160, 162, 164-167 syntax errors, 166 Ubuntu instance, 160, 162 uWSGI, 160, 162, 164-167 AWS Elastic Beanstalk, 172 Google Cloud App Engine, 180-182 Heroku Gunicorn, 177-179 PaaS, 176 Procfile, 177-179 Elastic Beanstalk application AWS, 172 configuration, 174 deployed flask app, 176 eb create, 173 environment variables, 175 WSGlpath set, 174 F find_by_username() method, 92 Flask application, 2, 3 components, 1-4 installation, 25 python development environment IDE setup, 18, 19 PIP installation, 16-18 running virtual application, 23, 24 virtual directory structure, 21,22 virtualeny, 20 SQLAlchemy, 4 Flask Monitoring Dashboard, 187 Flask-SQLAlchemy, 30 Flask-WhooshAlchemy, 193 G,H Google Cloud App Engine, 180-182 _init__py, 62 INDEX J, KL JSON Web Tokens (JWT), 89 Monitoring flask applications bonus services emails, 193, 194 Flask-WhooshAlchemy, 193 Pyelasticsearch, 192 flask monitoring dashboard, 187, 188 New Relic, 189-191 Sentry, 185-187 N New Relic, 189 O° Object Document Mapper (ODM), 28 Object Relational Mapper (ORM), 28 Object Storage Service (OSS), 194 OpenAPI Specification (OAS), 116 API request mode, 124 build time documentation author avatar endpoint, 132-134 create author endpoint, 130, 131 197 INDEX OpenAPI Specification (OAS) (cont) create user endpoint, 126, 127 Swagger UI, 128 using YAML, 127 definition, 116 importing OpenAPI from Inspector, 121 login endpoint, 119 pinned requests, 119 spec generation, 120 SwaggerHub, 122 Swagger Inspector, 117, 118 Swagger UI, 125 view documentation, 122, 123 P,Q Platform as a Service (PaaS), 176 Pyelasticsearch, 192 Python Package Index (PPI), 2 R render_template_string method, 104 Representational State Transfer (REST) API design, 15, 16 architecture, 6 definition, 4 services 198 caching technique, 13 messages, 9-12 planning, 14, 15 representation, 8 resources, 12 statelessness, 14 uniform interface, 7 used HTTP verbs, 8 SOAP, 6 response_with function, 70 Ss Sentry, 185 Simple Object Access Protocol (SOAP), 6 Structured Query Language (SQL), 28 T test_login_unverified_user() method, 143 test_login_user_wrong_credentials method, 143 U Unit testing benefits, 136 setting up, 136-138 test coverage, 155 user endpoints assertion methods, 140 authors test, 151, 153, 155 create temp image file, 149 create test_authors.py, 146 create_user endpoint, 143, 144 create_users() method, 144 creating author without last_name field, 148 CSV file, 149 delete author object, 151 generate login token, 146 GET author ID, 150 POST author endpoint, 147 INDEX running with nose, 142 SQLAlchemy model, 139 test login API, 142 TestUsers() class, 140 test_users.py, 139 update author object, 150 Virtualeny, 20 W, X, Y, Z Web Server Gateway Interface (WSGI), 1

You might also like