159 lines
4.2 KiB
TeX
159 lines
4.2 KiB
TeX
\documentclass[10pt,aspectratio=169]{beamer}
|
|
|
|
\usetheme[progressbar=frametitle]{metropolis}
|
|
\input{color_config.tex}
|
|
\usepackage{appendixnumberbeamer}
|
|
\usepackage{svg}
|
|
\usepackage{booktabs}
|
|
\usepackage{listings}
|
|
\usepackage[scale=2]{ccicons}
|
|
|
|
\usepackage{pgfplots}
|
|
\usepgfplotslibrary{dateplot}
|
|
|
|
\usepackage{xspace}
|
|
\newcommand{\themename}{\textbf{\textsc{metropolis}}\xspace}
|
|
|
|
\makeatletter
|
|
\setbeamertemplate{frametitle}{%
|
|
\nointerlineskip%
|
|
\begin{beamercolorbox}[%
|
|
wd=\paperwidth,%
|
|
sep=0pt,%
|
|
leftskip=\metropolis@frametitle@padding,%
|
|
rightskip=\metropolis@frametitle@padding,%
|
|
]{frametitle}%
|
|
\metropolis@frametitlestrut@start%
|
|
\insertframetitle%
|
|
\nolinebreak%
|
|
\metropolis@frametitlestrut@end%
|
|
\hfill
|
|
\raisebox{-0.6ex}{\includegraphics[height=6ex,keepaspectratio]{logo-hadinet-darkmode.png}}
|
|
\end{beamercolorbox}%
|
|
}
|
|
\setbeamertemplate{title page}{
|
|
\begin{minipage}[\paperheight]{\textwidth}
|
|
\ifx\inserttitle\@empty\else\usebeamertemplate*{title}\fi
|
|
\ifx\insertsubtitle\@empty\else\usebeamertemplate*{subtitle}\fi
|
|
\usebeamertemplate*{title separator}
|
|
\begin{columns}
|
|
\begin{column}{.6\textwidth}
|
|
\ifx\beamer@shortauthor\@empty\else\usebeamertemplate*{author}\fi
|
|
\ifx\insertdate\@empty\else\usebeamertemplate*{date}\fi
|
|
\ifx\insertinstitute\@empty\else\usebeamertemplate*{institute}\fi
|
|
\vfill
|
|
\end{column}
|
|
\begin{column}{.3\textwidth}
|
|
\vfill\hfill
|
|
\includegraphics[height=.4\textheight,keepaspectratio]{logo-hadinet-darkmode.png}
|
|
\end{column}
|
|
\end{columns}
|
|
\vfill
|
|
\end{minipage}
|
|
}
|
|
\makeatother
|
|
|
|
\DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{12} % for bold
|
|
\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{12} % for normal
|
|
\usepackage{xcolor}
|
|
\definecolor{keyword}{RGB}{138, 172, 201}
|
|
\definecolor{class}{RGB}{205, 138, 196}
|
|
\definecolor{string}{RGB}{121, 189, 139}
|
|
\newcommand\pythonstyle{\lstset{
|
|
language=Python,
|
|
basicstyle=\ttm\small,
|
|
morekeywords={self},
|
|
keywordstyle=\ttb\small\color{keyword},
|
|
emph={StudentRoom,FastAPI},
|
|
emphstyle=\ttb\small\color{class},
|
|
stringstyle=\color{string},
|
|
frame=tb,
|
|
showstringspaces=false
|
|
}}
|
|
|
|
\title{Pydantic}
|
|
\subtitle{Favorite Tool for Data Validation in python}
|
|
% \date{\today}
|
|
\date{31.08.2023}
|
|
\author{Lewi}
|
|
\institute{}
|
|
% \titlegraphic{\hfill\includegraphics[height=1.5cm]{logo.pdf}}
|
|
|
|
\begin{document}
|
|
|
|
\maketitle
|
|
\begin{frame}{dataclasses}
|
|
\begin{itemize}
|
|
\item
|
|
\end{itemize}
|
|
\end{frame}
|
|
\begin{frame}{Why Pydantic}
|
|
\begin{itemize}
|
|
\item Encourages Usage of Type Hints
|
|
\item Fast
|
|
\item Autogenerates JSON Schema
|
|
\item Complete custom validation
|
|
\item Used in many other useful Frameworks
|
|
\item Awesome Documentation
|
|
\end{itemize}
|
|
\end{frame}
|
|
\begin{frame}[fragile]{Basics}
|
|
\pythonstyle
|
|
\begin{lstlisting}[language=Python]
|
|
from pydantic import BaseModel
|
|
|
|
class StudentRoom(BaseModel):
|
|
room_number: str
|
|
rent: int
|
|
|
|
r = StudentRoom(room_number='a111', rent=250)
|
|
print(r.room_number)
|
|
# > a111
|
|
r2 = StudentRoom(room_number='a111', rent=[250])
|
|
# > Input should be a valid integer
|
|
# > [type=int_type, input_value=[250], input_type=list]
|
|
\end{lstlisting}
|
|
\end{frame}
|
|
\begin{frame}{What to use it for?}
|
|
\begin{itemize}
|
|
\item Configuration Validation
|
|
\item Data Modeling
|
|
\item REST Validation
|
|
\end{itemize}
|
|
\end{frame}
|
|
\begin{frame}[fragile]{JSON Schema}
|
|
\pythonstyle
|
|
\begin{lstlisting}[language=Python]
|
|
StudentRoom.model_json_schema()
|
|
# > {'properties': {
|
|
# > 'room_number': {'title': 'Room Number', 'type': 'string'},
|
|
# > 'rent': {'title': 'Rent', 'type': 'integer'}
|
|
# > },
|
|
# > 'required': ['room_number', 'rent'],
|
|
# > 'title': 'StudentRoom',
|
|
# > 'type': 'object'
|
|
# > }
|
|
\end{lstlisting}
|
|
\end{frame}
|
|
\begin{frame}[fragile]{FastApi}
|
|
\pythonstyle
|
|
\begin{lstlisting}[language=Python]
|
|
from typing import Union
|
|
|
|
from fastapi import FastAPI
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/")
|
|
def read_root():
|
|
return {"Hello": "World"}
|
|
|
|
|
|
@app.get("/items/{item_id}")
|
|
def read_item(item_id: int, q: Union[str, None] = None):
|
|
return {"item_id": item_id, "q": q}
|
|
\end{lstlisting}
|
|
\end{frame}
|
|
\end{document}
|