SlideShare une entreprise Scribd logo
1  sur  61
Télécharger pour lire hors ligne
Python Developer's
Daily Routine
Maxim Avanov (github.com/avanov)
Project structure
3

Project structure
.cei
/hbt
|-cei
- hbt
|

`-_ii_.y
- _nt_p

`-stpp
- eu.y
4

setup.py
fo stpol ipr stp fn_akgs
rm eutos mot eu, idpcae
stp
eu(
nm=Cei'
ae'hbt,
vrin'..'
eso=001,
pcae=idpcae(,
akgsfn_akgs)
ts_ut=tss,
etsie'et'
tssrqie[pts' 'oeae]
et_eur='yet, cvrg',
isalrqie='yai=152]
ntl_eurs[Prmd=.a'
)
5

Bootstrapping
$ python setup.py install
$ python setup.py develop
$ python setup.py test
$ python setup.py regtister sdist [bdist_egg] upload
Package
management
7

pip commands
$ppisalPrmd
i ntl yai
$ppisalPrmd-ugae
i ntl yai -prd
$ppisalPrmd=.a -ugae
i ntl yai=152 -prd
$ppuisalPrmd
i nntl yai
8

pip commands
$ppfez
i ree
Bbl=.
ae=13
Cei=001
hbt=..
CfeSrp=108
ofecit=..
Jna=271
ij2=..
Mk=090
ao=..
..
.
9

pip-tools
$pprve
i-eiw
rqet=01. aalbe(o hv 01.)
euss=.34 vial yu ae .32

$pprve -at
i-eiw -uo
..<i isalotu>
. pp ntl upt

$pprve -itrcie
i-eiw -neatv
rqet=01. aalbe(o hv 01.)
euss=.40 vial yu ae .32
Ugaenw []s [],[]l []i y
prd o? Ye, No Al, Qut
..
.
10

Cookiecutter
• Generates initial project files from defined templates;
• File names are also templates;
• Transparently works with remote VCS.
11

Cookiecutter template
.cei-epae
/hbttmlt
|-coicte.sn
- okeutrjo
`-{coicte.rjc_ae}
- {okeutrpoetnm}
|-{coicte.rjc_ae}
- {okeutrpoetnm}
|

`-_ii_.y
- _nt_p

`-stpp
- eu.y
12

cookiecutter.json
{
"rjc_ae:"yrjc"
poetnm" mpoet,
"rjc_eso" ".."
poetvrin: 001
}
13

Cookiecutter in action
$coicte {rjc_epaept}
okeutr poettmlt_ah
poetnm (eal i "yrjc"?mnw
rjc_ae dfut s mpoet) ye
poetvrin(eal i ".."?011
rjc_eso dfut s 001) ..
$te .mnw
re /ye
.mnw
/ye
|-mnw
- ye
|

`-_ii_.y
- _nt_p

`-stpp
- eu.y
We'd like to
isolate project
environments
15

virtualenv
$vruln ~vn/poetnm}
itaev /ev{rjc_ae
$suc ~vn/poetnm}bnatvt
ore /ev{rjc_ae/i/ciae

What if we need another Python version?
$vruln ~vn/poetnm}- pto3
itaev /ev{rjc_ae p yhn
Still not happy
enough!
Introducing pyenv
18

pyenv - 5 steps to happiness
$gtcoegt/gtu.o/yupevgt~pev
i ln i:/ihbcmyu/yn.i /yn
$eh 'xotPEVRO=$OEpev'> ~.ahc
co epr YN_OT"HM/yn" > /bsr
$eh 'xotPT=$YN_OTbn$AH'> ~.ahc
co epr AH"PEVRO/i:PT" > /bsr
$eh 'vl"(yn ii -" > ~.ahc
co ea $pev nt )' > /bsr
$ee $HL
xc SEL
19

pyenv - Rise and Shine!
$pevisalyn ntl l
$pevisal276
yn ntl ..
$pevisal333
yn ntl ..
$pevisalpp-..
yn ntl yy221
$pevrhs
yn eah
20

The Happiness
$ pyenv versions
$ pyenv version
$ pyenv local 2.7.6 3.3.3
$ pyenv global 3.3.3
$ pyenv shell pypy-2.2.1
$ pyenv whence 2to3
21

...
$wihpto
hc yhn
/oegotrtrpevsispto
hm/hswie/yn/hm/yhn

$pto
yhn
Pto 273(7ad1fc Nv2 21,1:81)
yhn .. 8a9e09, o 4 03 84:3
[yy221wt GC463 o lnx
PP .. ih C ..] n iu2
>>
>>
virtualenv meets
pyenv
23

pyenv-virtualenv
$gtcoegt/gtu.o/yupev
i ln i:/ihbcmyu/ynvruln.i ~pevpuispevvruln
itaevgt /yn/lgn/yn-itaev

$pevvruln pp-.. ~vn/poetnm}
yn
itaev yy221 /ev{rjc_ae
24

pyenv-virtualenv in action
$pevvrulns
yn itaev
{rjc_ae (rae fo /oegotrtrpevvrin/yy221
poetnm} cetd rm hm/hswie/yn/esospp-..)

$suc ~pevvrin/poetnm}bnatvt
ore /yn/esos{rjc_ae/i/ciae
Well done!
Now, what about
other components?
Virtualization
28

Vagrant
• Written in Ruby
• Relies on VirtualBox
• Runs on Linux / OS X / Win
29

Juju
• Written in Python / Go
• Relies on LXC
• Linux only
30

Docker
• Written in Go
• Relies on LXC and AUFS
• Linux only
31

Vagrant's Success Story...
1. Put a Vagrantfile into the project root
2. $ vagrant up
3. $ vagrant ssh
4. Profit!
32

Vagrantfile
Vgatcniue"" d |ofg
arn.ofgr(2) o cni|
cni.mbx="rjc_ae
ofgv.o
poetnm"
cni.mbxul="tp/flsvgatpcmpeie4bx
ofgv.o_r
ht:/ie.arnu.o/rcs6.o"
cni.mntok:rvt_ewr,i:"9.6.310
ofgv.ewr piaentok p 12183.0"
ed
n
33

...Vagrant's Success Story
1. Put a Vagrantfile into the project root
2. $ vagrant up
3. $ vagrant ssh
4. Profit! ..???
5. Deployment
34

Deployment tools
Chef (Ruby)
Puppet (Ruby)
Ansible (Python)
Salt (Python)
35

Ansible Success Story
1. Specify an inventory file
2. Specify a playbook
3. $ ansible-playbook ./playbook.yml -i ./hosts
36

Ansible inventory
[eeo-m
dvlpv]
12183.0
9.6.310
37

Ansible playbook
-hss dvlpv
ot: eeo-m
sd:ys
uo e
tss
ak:
nm:esr atccei u t dt
ae nue p ah s p o ae
ato:atudt_ah=e
cin p paecceys

http://www.ansibleworks.com/docs/modules.html
38

Ansible meets Vagrant
$asbepabo .pabo.m - .hss- nil-lyok /lyokyl i /ot v
uvgat- prmk -piae
arn c aaio -rvtky$OE.arn./neuepiaeky
e=HM/vgatdiscr_rvt_e

or
$vgatpoiin
arn rvso
39

Ansible - Vagrant Integration
#Vgatie
arnfl
Vgatcniue"" d |ofg
arn.ofgr(2) o cni|

#..
.
cni.mpoiin:nil d |nil|
ofgv.rvso asbe o asbe
asbepabo ="/lyokyl
nil.lyok
.pabo.m"
asbeivnoypt ="/ot"
nil.netr_ah
.hss
asbevroe=""
nil.ebs
v
ed
n
ed
n
Python & Web
41

Web Server Gateway Interface
Standardized by PEP 333, PEP 3333

dfapiainevrn satrsos)
e plcto(nio, tr_epne:
satrsos(20O' ['otn-ye,'etpan))
tr_epne'0 K, (CnetTp' tx/li']
yed'el Wrdn
il Hlo ol'
42

WSGI Servers
• CherryPy WSGI Server
• gunicorn
• tornado.wsgi
• uWSGI
• Waitress

http://nichol.as/benchmark-of-python-web-servers
Frameworks
44

Heavyweights
• Django
• Twisted
• web2py
• Zope
45

Middleweights
• CherryPy
• Pyramid
• Tornado
• TurboGears
46

Flyweights
• Bottle
• Flask
• Webpy
Database Access
48

ORM
• SQLAlchemy ORM
• Django ORM (Django only)
• Pony ORM
• Peewee
49

Something else
• Native DB-API 2.0 (standardized with PEP 249)
• SQLAlchemy's raw queries
• mosql
50

SQL DDL Versioning & Data Migration
• South (Django only)
• Alembic (SQLAlchemy)
• Pyrseas
Background task
processing
52

Celery
• Out of the box solution for complex cases;
• Multiple brokers - RabbitMQ, Redis, RDBMS, SQS, MongoDB etc;
• Tasks scheduler;
• Results backends.
53

RQ (Redis Queue)
• Designed to have a low barrier to enter;
• Uses Redis' Pub/Sub feature.
Process managers
55

Process managers
• Supervisor
• Circus.io
Sentry
60

Testing tools
• unittest
• py.test
• nose
• WebTest
• coverage
• tox
Thank you!

Contenu connexe

Tendances

FrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав ВорончукFrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
GeeksLab Odessa
 
ใบงานเรื่องการคอมไพล์โปรแกรม
ใบงานเรื่องการคอมไพล์โปรแกรมใบงานเรื่องการคอมไพล์โปรแกรม
ใบงานเรื่องการคอมไพล์โปรแกรม
ธงชัย พาศรี
 

Tendances (20)

Remote IP Power Switches
Remote IP Power SwitchesRemote IP Power Switches
Remote IP Power Switches
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
FFT
FFTFFT
FFT
 
Parallel binary search
Parallel binary searchParallel binary search
Parallel binary search
 
TDDBC お題
TDDBC お題TDDBC お題
TDDBC お題
 
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав ВорончукFrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
FrontendLab: Programming UI with FRP and Bacon js - Вячеслав Ворончук
 
R で解く FizzBuzz 問題
R で解く FizzBuzz 問題R で解く FizzBuzz 問題
R で解く FizzBuzz 問題
 
FRP and Bacon.js
FRP and Bacon.jsFRP and Bacon.js
FRP and Bacon.js
 
A Backbone.js Tutorial for the Impatient - Part 1
A Backbone.js Tutorial for the Impatient - Part 1A Backbone.js Tutorial for the Impatient - Part 1
A Backbone.js Tutorial for the Impatient - Part 1
 
Mouse and Cat Game In C++
Mouse and Cat Game In C++Mouse and Cat Game In C++
Mouse and Cat Game In C++
 
Debugging: A Senior's Skill
Debugging: A Senior's SkillDebugging: A Senior's Skill
Debugging: A Senior's Skill
 
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlinYahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
 
Fabricでお手軽サーバ管理
Fabricでお手軽サーバ管理Fabricでお手軽サーバ管理
Fabricでお手軽サーバ管理
 
2c astable monostable
2c astable monostable2c astable monostable
2c astable monostable
 
03 tk2123 - pemrograman shell-2
03   tk2123 - pemrograman shell-203   tk2123 - pemrograman shell-2
03 tk2123 - pemrograman shell-2
 
going loopy - adventures in iteration with google go
going loopy - adventures in iteration with google gogoing loopy - adventures in iteration with google go
going loopy - adventures in iteration with google go
 
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of WranglingPLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
PLOTCON NYC: Behind Every Great Plot There's a Great Deal of Wrangling
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
ใบงานเรื่องการคอมไพล์โปรแกรม
ใบงานเรื่องการคอมไพล์โปรแกรมใบงานเรื่องการคอมไพล์โปรแกรม
ใบงานเรื่องการคอมไพล์โปรแกรม
 
Abusing Erlang compilation pipeline for Fun and Profit
Abusing Erlang compilation pipeline for Fun and ProfitAbusing Erlang compilation pipeline for Fun and Profit
Abusing Erlang compilation pipeline for Fun and Profit
 

Similaire à Python Developer's Daily Routine

pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
Command Prompt., Inc
 
Marko Gargenta_Remixing android
Marko Gargenta_Remixing androidMarko Gargenta_Remixing android
Marko Gargenta_Remixing android
Droidcon Berlin
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony components
Michael Peacock
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?
Lloyd Huang
 

Similaire à Python Developer's Daily Routine (20)

Bash tricks
Bash tricksBash tricks
Bash tricks
 
Seaborn graphing present
Seaborn graphing presentSeaborn graphing present
Seaborn graphing present
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Marko Gargenta_Remixing android
Marko Gargenta_Remixing androidMarko Gargenta_Remixing android
Marko Gargenta_Remixing android
 
Writing Faster Python 3
Writing Faster Python 3Writing Faster Python 3
Writing Faster Python 3
 
Angular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental FeatureAngular.js + Rails at WeWork or: The Accidental Feature
Angular.js + Rails at WeWork or: The Accidental Feature
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Unix 5 en
Unix 5 enUnix 5 en
Unix 5 en
 
Noah Zoschke at Waza 2013: Heroku Secrets
Noah Zoschke at Waza 2013: Heroku SecretsNoah Zoschke at Waza 2013: Heroku Secrets
Noah Zoschke at Waza 2013: Heroku Secrets
 
Refactoring to symfony components
Refactoring to symfony componentsRefactoring to symfony components
Refactoring to symfony components
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
PhpUnit Best Practices
PhpUnit Best PracticesPhpUnit Best Practices
PhpUnit Best Practices
 
Keep it simple web development stack
Keep it simple web development stackKeep it simple web development stack
Keep it simple web development stack
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in python
 
Django productivity tips and tricks
Django productivity tips and tricksDjango productivity tips and tricks
Django productivity tips and tricks
 
COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?COSCUP2012: How to write a bash script like the python?
COSCUP2012: How to write a bash script like the python?
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of Ruby
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Python Developer's Daily Routine