Data Validation & serialisation in Flask: Integration of Pydantic with Flask using Flask-Dantic

vivek keshore (~vivek17)


8

Votes

Description:

Abstract

The pain of data validation in Flask is very tiresome. Developers mostly make use of the json schema validation using Cerberus or use libraries like Marshmallow. In most of the cases it is observed that the developers either completely ignore the data validation, or just do it the raw way by implementing the validation code as part of API code. Imagine if the power of Pydantic can be harnessed inside Flask app, thus reducing the number of lines of validation and serialisation code by 90% and at the same time also increasing the effectiveness and robustness of the application. In this 30-minute talk, I will be introducing the self developed Flask-Dantic library, designed to simplify data validation and serialisation in Flask applications. This library seamlessly integrates the power of Pydantic, a data validation and serialisation library, with the flexibility of the Flask web framework. We would explore how Flask-Dantic streamlines the development process and enhances the reliability of your Flask APIs.

Outline of the talk

1. Existing Challenges in Data Validation and Serialization (5 mins)

  • Why data validation is important and needed.
  • Brief overview of how the data validation and serialisation is done currently in Flask.
  • What are the challenges that are encountered.

2. Brief intro to Pydantic (5 mins)

  • A very intro to Pydantic data models, and some of the validation techniques.

3. Introduction to Flask-Dantic (2 mins)

  • Introduction to the Flask-Dantic" library and its objectives.
  • Installation and setup of Flask-Dantic in a Flask project.

4. Flask-Dantic implementation in app: A powerful duo of Flask and Pydantic (8 mins)

  • Defining Pydantic models and integrating them into Flask routes.
  • Streamlining data validation.
  • Showcase how "Flask-Dantic" simplifies data validation.
  • Handling various data types, constraints, and custom validation logic.
  • Validation of Body, Path Params, Args Params, Headers using Flask-Dantic.

5. Effortless Serialization (5 minutes)

  • Discussing automatic serialisation of DB objects to JSON using Pydantic
  • Responses. Handling serialisation of complex nested structures.
  • Customising response code.

6. Conclusion (2 mins)

  • Take home points
  • Advantages and the challenges that were solved
  • Future enhancements

Prerequisites:

Basic knowledge of API development using Flask.

Content URLs:

https://pypi.org/project/flask-dantic/

Speaker Info:

I am a Python Enthusiast who loves building software applications and education related content. I am a technology professional and a passionate programmer with 11 years of experience in Python & Python related technologies. I am currently working as Architect at SenecaGlobal Inc, Hyderabad.

I have been involved with multiple professional projects in various industrial domains and technical fields. My expertise is in application development, data processing & analysis, data structures, & algorithms, various non-relational and relational databases, Python, Flask, FastAPI, Celery, RabbitMQ, Redis, Cassandra, AWS, Airflow, and various other tech stacks. I am also an open source contributor, and published self developed libraries on PyPI. I love creating libraries and various utility tools that help me in solving a challenge/problem that could also be used by others in the developers community.

My personal interest is in exploring new technologies, web application development, IoT systems, spread Python education, and read novels. I also write and share my thoughts occasionally on Quora and Medium.

Speaker Links:

Previous Proposals

  • https://in.pycon.org/cfp/2021/proposals/hows-the-job-title-quantum-computer-programmer~bmZQr/
  • https://in.pycon.org/cfp/2021/proposals/one-api-to-rule-them-all-config-based-development~en5rE/

PyPI Libraries

And many more in progress ...

Docker HUB

Rhinestone

Medium Articles (Published in NerdForTech and MLearning.ai)

https://vivek-keshore.medium.com

Github

Github

LinkedIn

LinkedIn

Section: Web & App development
Type: Talks
Target Audience: Beginner
Last Updated: