SlideShare a Scribd company logo
Complete Python toolbox for
modern developers
Jan Giacomelli
Python Web Conference 2021
About me
● Tech lead and co-founder typless.com
● Author at testdriven.io
● Twitter: @jangiacomelli
Python development
● creating and re-creating virtual environments
● installing, uninstalling, and updating dependencies
● type checking
● writing and running tests
● following consistent code style
● avoiding security vulnerabilities
● documenting code
Modern Python Environments - pyenv
Lets you easily switch between multiple versions of Python.
● Install specific Python version: $ pyenv install 3.8.5
● List available Python versions: $ pyenv versions
Modern Python Environments - pyenv
● Select a specific version as a global default: $ pyenv global 3.8.5
● Select a specific version for the current project: $ pyenv local 3.9.0
Modern Python Environments - pip + venv
Fairly simple to use. Pre-installed with most versions of Python.
● Create virtual environment: $ python -m venv my_venv
● Activate virtual environment: $ source my_venv/bin/activate
● Install a dependency: (my_venv)$ python -m pip install <package-name>
● Create list of dependencies: (my_venv)$ python -m pip freeze > requirements.txt
Modern Python Environments - pip + venv
Modern Python Environments - Poetry
Powerful CLI used for creating and managing Python projects.
● Create a new project: $ poetry new <project-name>
● Install a dependency: $ poetry add [--dev] <package name>
● Run a command inside the virtual environment: $ poetry run python -m pytest
● Dependencies are managed inside pyproject.toml
Modern Python Environments - Poetry
Modern Python Environments - pipenv
Managing dependencies and virtual environments.
● Create virtual environment: $ pipenv --python 3.8
● Install a dependency: $ pipenv install [--dev] <package name>
● Run a command inside the virtual environment: $ pipenv run python -m pytest
● Dependencies are managed inside Pipfile
Modern Python Environments - pipenv
Which one to choose?
● pip + venv
● poetry
● pipenv
Python testing - pytest
Go-to testing framework for testing Python code.
Compared to unittest:
● less boilerplate code -> more readable test suites
● uses built-in assert statement -> more readable and easier to remember
● updated more frequently (not part of the Python standard library)
● simpler setting up and tearing down test state with its fixture system
● uses a functional approach
Python testing - pytest
Python testing - pytest
Python testing - pytest
Plugins:
● pytest-django - set of tools made specifically for testing Django applications
● pytest-xdist - run tests in parallel
● pytest-cov - adds code coverage support
● pytest-instafail - shows failures and errors immediately instead of waiting until the end of a run
Python testing - Mocking
Practice of replacing real objects with
mocked ones, which mimic their
behavior, at runtime.
Python testing - Mocking
● pytest’s monkeypatch
● Python’s built-in untttest.mock library
○ Mock
○ MagicMock
○ create_autospec
Python testing - Code coverage
A metric that tells you the ratio between the
number of lines executed during test runs and
the total number of all lines in your code base.
pytest-cov - adds code coverage support
Code quality
Code is considered to be of high quality when:
● It serves its purpose
● Its behavior can be tested
● It follows a consistent style
● It's understandable
● It doesn't contain security vulnerabilities
● It's documented well
● It's easy to maintain
Code quality - linters
Linters flag programming errors, bugs, stylistic errors, and suspicious constructs through source code
analysis.
Code quality - flake8
Wrapper around Pyflakes, pycodestyle, and McCabe.
Code quality - flake8
Code quality - formatters
Reformat your code based on a set of standards.
Code formatting is a dull job that should be performed by a computer.
● reduce merge conflicts
● easier to read code
● easier to find bugs
● easier to onboard new developers
Code quality - isort
Automatically separates imports into groups standard library, third-party, local, and alphabetically
orders them.
Code quality - black
Code formatter that's used to reformat your code based on the Black's code style guide.
Code quality - black
Code quality - Security Vulnerability Scanners
Your code is only as secure as its weakest link.
Code quality - bandit
Tool designed to find common security issues in Python code.
● hardcoded password strings
● deserializing untrusted code
● using pass in except blocks
Code quality - safety
Used to check your installed dependencies for known security vulnerabilities against Safety database.
Type checking - type hints
Type hints allow developers to annotate expected types for variables, function parameters, and
function returns inside Python code.
● not enforced by the Python interpreter
● better express the intent
● autocomplete
● less bugs
Type checking - type hints
Type checking - type hints
Type checking - mypy
A tool for type checking at compile-time.
Type checking - pydantic
Uses type hints to validate data on runtime.
● easy to use
● uses type casting
● use it when dealing with external data
Type checking - pydantic
Type checking - Marshmallow
Helps to validate complex data and load/dump data from/to native Python types.
● doesn't use type casting
● schema and class defined separately
Type checking -
Marshmallow
Type checking - Typeguard
It enforces types while your program is running.
● typechecked decorator
● comes with pytest plugin
● for classes and functions
Type checking - Typeguard
Documenting Python Code
Without proper documentation, it can be very difficult or impossible for internal and external
stakeholders to use and/or maintain your code.
● standalone resource
● should always be present
● how and when to use something
Documenting Python Code - Docstrings
A special "string literal that occurs as the first
statement in a module, function, class, or method
definition".
● __doc__ attribute of module/class/function
● multiline and single line
● different formats (Google, NumPy,
reStructuredText, Epytext)
● code examples (doctest)
Documenting Python Code - Sphinx
Converts your project's docstrings to HTML and CSS.
Documenting Python Code - Sphinx
Documenting Python Code - Sphinx
Documenting Python Code - OpenAPI
Standard format for describing, producing,
consuming, and visualizing RESTful APIs.
● used for SwaggerUI and ReDoc
● can be imported to Postman
● can be used to generate SDKs
● can be auto-generated
Documenting Python Code - OpenAPI
Conclusion
● creating and re-creating virtual environments - pyenv, pip + venv, poetry, pipenv
● installing, uninstalling, and updating dependencies - pip + venv, poetry, pipenv
● writing and running tests - pytest, pytest-cov, unittest.mock
● type checking - mypy, pydantic, marshmallow, typeguard
● following consistent code style - black, flake8, isort
● avoiding security vulnerabilities - bandit, security
● documenting code - Sphinx, OpenAPI
You can learn more about these tools in Complete Python Guide

More Related Content

What's hot

Introduction to Robot Framework (external)
Introduction to Robot Framework (external)Introduction to Robot Framework (external)
Introduction to Robot Framework (external)
Zhe Li
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introduction
Pekka Klärck
 
Robot Framework with Python | Edureka
Robot Framework with Python | EdurekaRobot Framework with Python | Edureka
Robot Framework with Python | Edureka
Edureka!
 
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan PeshovJavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
ATDD Using Robot Framework
ATDD Using Robot FrameworkATDD Using Robot Framework
ATDD Using Robot Framework
Pekka Klärck
 
Pentester++
Pentester++Pentester++
Pentester++
CTruncer
 
Learning Python with PyCharm EDU
Learning Python with PyCharm EDU Learning Python with PyCharm EDU
Learning Python with PyCharm EDU
Sergey Aganezov
 
Sonarqube + Docker
Sonarqube + DockerSonarqube + Docker
Sonarqube + Docker
Estefanía Fernández Muñoz
 
Robot framework
Robot frameworkRobot framework
Robot framework
boriau
 
The Veil-Framework
The Veil-FrameworkThe Veil-Framework
The Veil-Framework
VeilFramework
 
JenkinsPy workshop
JenkinsPy workshop JenkinsPy workshop
JenkinsPy workshop
Haifa Ftirich
 
Windows Offender: Reverse Engineering Windows Defender's Antivirus Emulator
Windows Offender: Reverse Engineering Windows Defender's Antivirus EmulatorWindows Offender: Reverse Engineering Windows Defender's Antivirus Emulator
Windows Offender: Reverse Engineering Windows Defender's Antivirus Emulator
Priyanka Aash
 
Tracking and improving software quality with SonarQube
Tracking and improving software quality with SonarQubeTracking and improving software quality with SonarQube
Tracking and improving software quality with SonarQube
Patroklos Papapetrou (Pat)
 
AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0
CTruncer
 
FRIDA 101 Android
FRIDA 101 AndroidFRIDA 101 Android
FRIDA 101 Android
Tony Thomas
 
Rfselenium2 redhat
Rfselenium2 redhatRfselenium2 redhat
Rfselenium2 redhat
Joonas Jauhiainen
 
A journey with Target Platforms
A journey with Target PlatformsA journey with Target Platforms
A journey with Target Platforms
Mickael Istria
 
TDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and GomegaTDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and Gomega
Eddy Reyes
 
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
A Battle Against the Industry - Beating Antivirus for Meterpreter and MoreA Battle Against the Industry - Beating Antivirus for Meterpreter and More
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
CTruncer
 
Code Quality Lightning Talk
Code Quality Lightning TalkCode Quality Lightning Talk
Code Quality Lightning Talk
Jonathan Gregory
 

What's hot (20)

Introduction to Robot Framework (external)
Introduction to Robot Framework (external)Introduction to Robot Framework (external)
Introduction to Robot Framework (external)
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introduction
 
Robot Framework with Python | Edureka
Robot Framework with Python | EdurekaRobot Framework with Python | Edureka
Robot Framework with Python | Edureka
 
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan PeshovJavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
 
ATDD Using Robot Framework
ATDD Using Robot FrameworkATDD Using Robot Framework
ATDD Using Robot Framework
 
Pentester++
Pentester++Pentester++
Pentester++
 
Learning Python with PyCharm EDU
Learning Python with PyCharm EDU Learning Python with PyCharm EDU
Learning Python with PyCharm EDU
 
Sonarqube + Docker
Sonarqube + DockerSonarqube + Docker
Sonarqube + Docker
 
Robot framework
Robot frameworkRobot framework
Robot framework
 
The Veil-Framework
The Veil-FrameworkThe Veil-Framework
The Veil-Framework
 
JenkinsPy workshop
JenkinsPy workshop JenkinsPy workshop
JenkinsPy workshop
 
Windows Offender: Reverse Engineering Windows Defender's Antivirus Emulator
Windows Offender: Reverse Engineering Windows Defender's Antivirus EmulatorWindows Offender: Reverse Engineering Windows Defender's Antivirus Emulator
Windows Offender: Reverse Engineering Windows Defender's Antivirus Emulator
 
Tracking and improving software quality with SonarQube
Tracking and improving software quality with SonarQubeTracking and improving software quality with SonarQube
Tracking and improving software quality with SonarQube
 
AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0
 
FRIDA 101 Android
FRIDA 101 AndroidFRIDA 101 Android
FRIDA 101 Android
 
Rfselenium2 redhat
Rfselenium2 redhatRfselenium2 redhat
Rfselenium2 redhat
 
A journey with Target Platforms
A journey with Target PlatformsA journey with Target Platforms
A journey with Target Platforms
 
TDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and GomegaTDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and Gomega
 
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
A Battle Against the Industry - Beating Antivirus for Meterpreter and MoreA Battle Against the Industry - Beating Antivirus for Meterpreter and More
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
 
Code Quality Lightning Talk
Code Quality Lightning TalkCode Quality Lightning Talk
Code Quality Lightning Talk
 

Similar to Complete python toolbox for modern developers

Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
Stanislav Petrov
 
Python_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptxPython_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptx
lemonchoos
 
Build and deploy scientific Python Applications
Build and deploy scientific Python Applications  Build and deploy scientific Python Applications
Build and deploy scientific Python Applications
Ramakrishna Reddy
 
The New York Times: Sustainable Systems, Powered by Python
The New York Times: Sustainable Systems, Powered by PythonThe New York Times: Sustainable Systems, Powered by Python
The New York Times: Sustainable Systems, Powered by Python
All Things Open
 
Python Mastery: A Comprehensive Guide to Setting Up Your Development Environment
Python Mastery: A Comprehensive Guide to Setting Up Your Development EnvironmentPython Mastery: A Comprehensive Guide to Setting Up Your Development Environment
Python Mastery: A Comprehensive Guide to Setting Up Your Development Environment
Python Devloper
 
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Andrew Yatsenko
 
Software development practices in python
Software development practices in pythonSoftware development practices in python
Software development practices in python
Jimmy Lai
 
PhpStorm: Symfony2 Plugin
PhpStorm: Symfony2 PluginPhpStorm: Symfony2 Plugin
PhpStorm: Symfony2 Plugin
Haehnchen
 
Python Developer Certification
Python Developer CertificationPython Developer Certification
Python Developer Certification
Vskills
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
Chetan Giridhar
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
Mattupallipardhu
 
Introduction to Python.pdf
Introduction to Python.pdfIntroduction to Python.pdf
Introduction to Python.pdf
Rahul Mogal
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OS
Cisco Russia
 
Python programming 2nd
Python programming 2ndPython programming 2nd
Python programming 2nd
Aishwarya Deshmukh
 
Python Tutorial for Beginner
Python Tutorial for BeginnerPython Tutorial for Beginner
Python Tutorial for Beginner
rajkamaltibacademy
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
TIB Academy
 
Pipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as CodePipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as Code
Kris Buytaert
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
Diego Freniche Brito
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
Abid Malik
 
Introduction to Python Basics Programming
Introduction to Python Basics ProgrammingIntroduction to Python Basics Programming
Introduction to Python Basics Programming
Raveendra R
 

Similar to Complete python toolbox for modern developers (20)

Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
Python_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptxPython_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptx
 
Build and deploy scientific Python Applications
Build and deploy scientific Python Applications  Build and deploy scientific Python Applications
Build and deploy scientific Python Applications
 
The New York Times: Sustainable Systems, Powered by Python
The New York Times: Sustainable Systems, Powered by PythonThe New York Times: Sustainable Systems, Powered by Python
The New York Times: Sustainable Systems, Powered by Python
 
Python Mastery: A Comprehensive Guide to Setting Up Your Development Environment
Python Mastery: A Comprehensive Guide to Setting Up Your Development EnvironmentPython Mastery: A Comprehensive Guide to Setting Up Your Development Environment
Python Mastery: A Comprehensive Guide to Setting Up Your Development Environment
 
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
Code Quality Control in a PHP project. GeekTalks, Cherkassy 2020
 
Software development practices in python
Software development practices in pythonSoftware development practices in python
Software development practices in python
 
PhpStorm: Symfony2 Plugin
PhpStorm: Symfony2 PluginPhpStorm: Symfony2 Plugin
PhpStorm: Symfony2 Plugin
 
Python Developer Certification
Python Developer CertificationPython Developer Certification
Python Developer Certification
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
 
Introduction to Python.pdf
Introduction to Python.pdfIntroduction to Python.pdf
Introduction to Python.pdf
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OS
 
Python programming 2nd
Python programming 2ndPython programming 2nd
Python programming 2nd
 
Python Tutorial for Beginner
Python Tutorial for BeginnerPython Tutorial for Beginner
Python Tutorial for Beginner
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
 
Pipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as CodePipeline as code for your infrastructure as Code
Pipeline as code for your infrastructure as Code
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
 
Introduction to Python Basics Programming
Introduction to Python Basics ProgrammingIntroduction to Python Basics Programming
Introduction to Python Basics Programming
 

Recently uploaded

OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 

Recently uploaded (20)

OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 

Complete python toolbox for modern developers

  • 1. Complete Python toolbox for modern developers Jan Giacomelli Python Web Conference 2021
  • 2. About me ● Tech lead and co-founder typless.com ● Author at testdriven.io ● Twitter: @jangiacomelli
  • 3. Python development ● creating and re-creating virtual environments ● installing, uninstalling, and updating dependencies ● type checking ● writing and running tests ● following consistent code style ● avoiding security vulnerabilities ● documenting code
  • 4. Modern Python Environments - pyenv Lets you easily switch between multiple versions of Python. ● Install specific Python version: $ pyenv install 3.8.5 ● List available Python versions: $ pyenv versions
  • 5. Modern Python Environments - pyenv ● Select a specific version as a global default: $ pyenv global 3.8.5 ● Select a specific version for the current project: $ pyenv local 3.9.0
  • 6. Modern Python Environments - pip + venv Fairly simple to use. Pre-installed with most versions of Python. ● Create virtual environment: $ python -m venv my_venv ● Activate virtual environment: $ source my_venv/bin/activate ● Install a dependency: (my_venv)$ python -m pip install <package-name> ● Create list of dependencies: (my_venv)$ python -m pip freeze > requirements.txt
  • 8. Modern Python Environments - Poetry Powerful CLI used for creating and managing Python projects. ● Create a new project: $ poetry new <project-name> ● Install a dependency: $ poetry add [--dev] <package name> ● Run a command inside the virtual environment: $ poetry run python -m pytest ● Dependencies are managed inside pyproject.toml
  • 10. Modern Python Environments - pipenv Managing dependencies and virtual environments. ● Create virtual environment: $ pipenv --python 3.8 ● Install a dependency: $ pipenv install [--dev] <package name> ● Run a command inside the virtual environment: $ pipenv run python -m pytest ● Dependencies are managed inside Pipfile
  • 12. Which one to choose? ● pip + venv ● poetry ● pipenv
  • 13. Python testing - pytest Go-to testing framework for testing Python code. Compared to unittest: ● less boilerplate code -> more readable test suites ● uses built-in assert statement -> more readable and easier to remember ● updated more frequently (not part of the Python standard library) ● simpler setting up and tearing down test state with its fixture system ● uses a functional approach
  • 16. Python testing - pytest Plugins: ● pytest-django - set of tools made specifically for testing Django applications ● pytest-xdist - run tests in parallel ● pytest-cov - adds code coverage support ● pytest-instafail - shows failures and errors immediately instead of waiting until the end of a run
  • 17. Python testing - Mocking Practice of replacing real objects with mocked ones, which mimic their behavior, at runtime.
  • 18. Python testing - Mocking ● pytest’s monkeypatch ● Python’s built-in untttest.mock library ○ Mock ○ MagicMock ○ create_autospec
  • 19. Python testing - Code coverage A metric that tells you the ratio between the number of lines executed during test runs and the total number of all lines in your code base. pytest-cov - adds code coverage support
  • 20. Code quality Code is considered to be of high quality when: ● It serves its purpose ● Its behavior can be tested ● It follows a consistent style ● It's understandable ● It doesn't contain security vulnerabilities ● It's documented well ● It's easy to maintain
  • 21. Code quality - linters Linters flag programming errors, bugs, stylistic errors, and suspicious constructs through source code analysis.
  • 22. Code quality - flake8 Wrapper around Pyflakes, pycodestyle, and McCabe.
  • 23. Code quality - flake8
  • 24. Code quality - formatters Reformat your code based on a set of standards. Code formatting is a dull job that should be performed by a computer. ● reduce merge conflicts ● easier to read code ● easier to find bugs ● easier to onboard new developers
  • 25. Code quality - isort Automatically separates imports into groups standard library, third-party, local, and alphabetically orders them.
  • 26. Code quality - black Code formatter that's used to reformat your code based on the Black's code style guide.
  • 27. Code quality - black
  • 28. Code quality - Security Vulnerability Scanners Your code is only as secure as its weakest link.
  • 29. Code quality - bandit Tool designed to find common security issues in Python code. ● hardcoded password strings ● deserializing untrusted code ● using pass in except blocks
  • 30. Code quality - safety Used to check your installed dependencies for known security vulnerabilities against Safety database.
  • 31. Type checking - type hints Type hints allow developers to annotate expected types for variables, function parameters, and function returns inside Python code. ● not enforced by the Python interpreter ● better express the intent ● autocomplete ● less bugs
  • 32. Type checking - type hints
  • 33. Type checking - type hints
  • 34. Type checking - mypy A tool for type checking at compile-time.
  • 35. Type checking - pydantic Uses type hints to validate data on runtime. ● easy to use ● uses type casting ● use it when dealing with external data
  • 36. Type checking - pydantic
  • 37. Type checking - Marshmallow Helps to validate complex data and load/dump data from/to native Python types. ● doesn't use type casting ● schema and class defined separately
  • 39. Type checking - Typeguard It enforces types while your program is running. ● typechecked decorator ● comes with pytest plugin ● for classes and functions
  • 40. Type checking - Typeguard
  • 41. Documenting Python Code Without proper documentation, it can be very difficult or impossible for internal and external stakeholders to use and/or maintain your code. ● standalone resource ● should always be present ● how and when to use something
  • 42. Documenting Python Code - Docstrings A special "string literal that occurs as the first statement in a module, function, class, or method definition". ● __doc__ attribute of module/class/function ● multiline and single line ● different formats (Google, NumPy, reStructuredText, Epytext) ● code examples (doctest)
  • 43. Documenting Python Code - Sphinx Converts your project's docstrings to HTML and CSS.
  • 46. Documenting Python Code - OpenAPI Standard format for describing, producing, consuming, and visualizing RESTful APIs. ● used for SwaggerUI and ReDoc ● can be imported to Postman ● can be used to generate SDKs ● can be auto-generated
  • 48. Conclusion ● creating and re-creating virtual environments - pyenv, pip + venv, poetry, pipenv ● installing, uninstalling, and updating dependencies - pip + venv, poetry, pipenv ● writing and running tests - pytest, pytest-cov, unittest.mock ● type checking - mypy, pydantic, marshmallow, typeguard ● following consistent code style - black, flake8, isort ● avoiding security vulnerabilities - bandit, security ● documenting code - Sphinx, OpenAPI You can learn more about these tools in Complete Python Guide

Editor's Notes

  1. Lock file
  2. There are also other options.
  3. PEP-8 - lower case function names, logic errors like posibility for undefined variable