I always used Django at work and for my personal projects. But on the recent project at work I had an opportunity to use Flask with SQLAlchemy. So I had to learn something new. Flask is easy peasy because it’s a microframework and it doesn’t have a lot inside. However, understanding SQLAlchemy and how to work with it was more difficult than I expected. In…
Django + Elasticsearch. Searching for awesome TED Talks
In the article we’re going to cover the basics of Elasticsearch: what it is, how to run it, how to communicate with it. Then, after we feel comfortable with Elasticsearch, we will start developing a simple web application with Django that will use the power of Elasticsearch. Running Elasticsearch Before diving into the concepts of Elasticsearch we should run it first. When you start reading…
Tale about Redis and sessions in Django
In this article we will learn the basics of Redis: what it is, how it stores data and what data structures it provides. Then we will take a look at session framework in Django. First we will learn how it works and then we will implement our own session engine that stores session data in Redis. It will be a great example for learning how…
Distributed systems with RabbitMQ
In this article we’re going to talk about the benefits of distributed systems and how to move to distributed systems using RabbitMQ. Then we will learn the fundamentals of RabbitMQ and how to interact with it using Python. Distributed systems Imagine that we’re building an ecommerce site. When the user makes an order, besides creating a row in the database, we also need to send…
Django + GraphQL. Solving N+1 Problem using DataLoaders
In this article we’re going to focus on specific problem which you will probably face if you start developing GraphQL APIs. I will try to explain the problem first and then show you how it can be solved using DataLoaders. N+1 Problem Imagine that you’re developing a blog. Your server should provide GraphQL API so that your client app written in React, Vue or Angular…
Let’s talk about data structures in Python
Data structures is a way to store and organize data. Obviously, some data structures are good in one set of problems, but terrible in other ones. The right choice of data structure can make your code faster, more efficient with memory and even more readable for other human beings. In this article we are going to discuss the most important data structures in python. How…
Django + React + TS. How to create and consume GraphQL API
This article is dedicated to GraphQL. I will explain what GraphQL is and what advantages it has over REST. Then we will create a simple web application that exposes GraphQL API on server-side and consumes it on client-side. Stack on server-side: Python; Django; Graphene Django for creating GraphQL API. Stack on client-side: TypeScript; React; React Apollo for interacting with GraphQL API. Also I will show…
Как начать Django проект, который можно масштабировать
В статье создадим проект используя шаблонизатор cookiecutter-django, настроим статическую типизацию, добавим автоматическое форматирование кода с помощью black, создадим скрипт, который запускает тесты, проверяет правильность типов через линтер mypy и стиль кода через black. Напоследок добавим пре-коммит хук, который автоматически запускает скрипт с проверками перед каждым коммитом. Содержание Создаем проект с помощью cookiecutter-django Библиотеки Настройки Веб-сервер и Gunicorn Запускаем проект Настраиваем статическую типизацию Форматируем код с…
Celery + Channels = <3. Создаем реал-тайм приложение с бэкграунд тасками
В статье создадим веб-приложение, которое в бэкграунде делает запросы к API со случайными шутками каждые 15 секунд, затем отправляет шутку пользователю через WebSocket. Для реализации приложения будем использовать: django, celery и channels. Celery для бэкграунд задач. Channels для передачи сообщений через WebSocket. Конечный результат на картинке: Исходный код проекта: https://github.com/apirobot/django-channels-celery-jokes Содержание Что такое celery Что такое channels Создаем проект Создаем приложение Создаем бэкграунд задачу Подключаем библиотеку…
Django + Vue. Реализуем вход через Google
Никто не любит при регистрации на сайте вводить каждый раз одно и то же: имя пользователя, электронную почту и т.д. Либо постоянно создавать и запоминать новые пароли. По этой причине, вход через сторонние приложения вроде Google, Facebook или VK очень популярен. Такие сторонние приложения используют протокол OAuth2. В статье я не буду объяснять, что это за протокол и как его реализовать. Вместо этого реализуем вход…