September 6, 2020

Testing database with pytest

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins We are going to use a database in our number testing application as a cache for API call results - API calls can be costly and we don’t want to check the same number twice against it. Read more

September 6, 2020

Testing HTTP client with pytest

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins Now let’s move to checking if the number exists or not. For that, we are going to employ a 3rd party API. According to API docs: It’s a REST API We need to use HTTP GET We provide a number in query parameters The result is a json {‘existing’: True | False} I’m going to create this 3rd party API myself and run it from my local environment so we can see the access logs. Read more

September 6, 2020

Types of tests

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins There are many types of tests. Brian Marick came up with this chart, which is widely used to show which types you should care about in order to deliver a high-quality application. In this diagram, he categorized tests according to whether they are business-facing or technology-facing, and whether they support the development process or are used to critique the project. Read more

September 6, 2020

Why testing is important

Other pytest articles: Why testing is important Types of tests Test driven Development Hello, World! Selecting tests with pytest Testing HTTP client with pytest Testing database with pytest Advanced fixtures with pytest Pytest plugins Testing makes our code flexible, reliable and reusable. Flexible If you don’t have tests for your code - every change to the code is a possible bug. Thus, developers fear making changes and implementing new features, no matter how flexible the architecture of the application is. Read more

August 23, 2020

Producer consumer pattern for fast data pipelines

Let’s build a simple data pipeline. It will read a SOURCE table in MySQL database. This table has only one column VALUES and contains 1000 rows - numbers from 1 to 1000. The application will calculate square root of the number and put the result in DESTINATION table. This table will have 2 columns VALUE column holding original number ROOT column for the result of calculation Very simple implementation of this pipeline can be like this one: Read more

August 13, 2020

Speeding up Python code with Cython

Cython is an extension of Python, that adds static typing to variables, functions and classes. It combines simplicity of Python and efficiency of C. You can rewrite your code in Cython and compile them to C to achieve higher execution speed. In this tutorial, you’ll learn how to: Install Cython and Compile Cython code something about speed Write Cython application with statically typed variables and C functions What Cython is and what it’s used for The Cython project consists of two parts - a programming language and a compiler. Read more

July 9, 2020

Accepting payments in Flask with Stripe

Introduction In this article you’ll learn how to use Stripe Checkout to accept one time payments in Flask application. THe example will be a webshop, that has a single page for selling 5$ T-shirts. Main page Create a Flask route that serves the webshop page. The page loads some JavaScript as well: a Stripe JS jQuery for AJAX call some custom JavaScript @app.route('/') def webshop(): return """<html> <head></head> <body> <a href="#" id="checkout">Buy T-shirt for 5$</a> <script src="https://code. Read more

May 7, 2020

How to increase Flask performance

When Flask app runs slow we need to identify what is the bottleneck. It can be an overloaded database, unresponsive external API, or heavy, CPU-intensive computation. This is the whole recipe on how to speed up Flask - find the source of sluggish performance. After the bottleneck is identified you can fight an underlying cause. And here I assume that the underlying platform that runs Flask has enough resources to do so. Read more

April 12, 2020

5 ways to deploy Flask

In this post, I’m going to explore 5 ways to deploy a Flask application. In all examples I’m going to use a simple app from Flask docs: app.py from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == '__main__': app.run() Local machine This option is used when you need to test your application on a local machine. By simply running app. Read more

November 4, 2019

Python linters for better code quality

Code quality There are two types of software quality - external and internal. External are the ones that are important to the users of the system. They may include: correctness - software behaves as users expect usability - how easy is it to use reliability - the ability to function under any circumstances Internal quality characteristics are what developers care about: maintainability - how easy the software can be modified readability - how easy new developers can understand what code is doing by reading it testability - how easy the systems could be tested to verify that it satisfies the requirements The internal characteristics relate closely with the quality of the code and design. Read more

© Alexey Smirnov 2021