Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Structuring Your Python Project
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Matt Bachmann
January 20, 2016
Programming
1
4k
Structuring Your Python Project
For people who know some Python and want to structure their first project
Matt Bachmann
January 20, 2016
Tweet
Share
More Decks by Matt Bachmann
See All by Matt Bachmann
Property Based Testing: Hypothesis
bachmann1234
0
780
Diff-Cover
bachmann1234
1
260
Opening The Floodgates: Unicode Identifiers in Python
bachmann1234
0
350
Other Decks in Programming
See All in Programming
AI巻き込み型コードレビューのススメ
nealle
0
120
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
690
AI時代の認知負荷との向き合い方
optfit
0
150
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
1.1k
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
640
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
2026年 エンジニアリング自己学習法
yumechi
0
130
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.3k
AgentCoreとHuman in the Loop
har1101
5
220
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
200
Grafana:建立系統全知視角的捷徑
blueswen
0
330
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
610
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
110
How GitHub (no longer) Works
holman
316
140k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
110
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.6k
Building AI with AI
inesmontani
PRO
1
680
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
54
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
160
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Transcript
Structuring Your Python Project Matt Bachmann
Agenda • Directory Structure • Isolating Your Environment • Installing
Dependencies • Packaging Your Project • Releasing to the World
Our Project • Display Current Weather > forcastio 42.3907 -71.1157
Currently: rain - Mixed precipitation tomorrow through Thursday, with temperatures falling to 41°F on Monday.
Project Structure
The Code
Style Checking Your Code
The Tests
Running Your Tests
License
Documentation
Documentation • All projects should have a readme ◦ Description
◦ Installation ◦ Usage • Moving Beyond Readme! ◦ Sphinx • Write docs in reStructuredText ◦ Renders in Github and PyPi. PyPi does not support Markdown
Specifying Dependencies and Isolating Your Project
Isolate Your Project • Install virtualenv > pip install virtualenv
• Create an isolated environment > virtualenv venv • Turn that environment on > source venv/bin/activate
Installing Dependencies Install a package pip install <package name> Upgrade
a package pip install -U <package name> Uninstall a package pip uninstall <package name> List Installed packages pip freeze Install packages from a file pip install -r <requirements file>
Installing Dependencies • requirements.txt requests==2.8.1 • test-requirements.txt coverage==4.0.3 flake8==2.5.0 mock==1.3.0
pyflakes==1.0.0 pytest==2.8.3
Deploying Your Project
Setup.py setup( name='displayforecastio', version='1.0', author='Matt Bachmann', url='https://github.com/Bachmann1234/displayforecastio', description='Display the current
weather in your terminal', license='Apache 2.0', packages=[‘displayforecastio'], install_requires=['requests==2.8.1'], entry_points={ 'console_scripts': ['forcastio = displayforecastio.app:run'], } )
What This Gives You • Install your project from project
root > pip install . • After installation you have a command! > forecastio 42.3907 -71.1157 • Share your project with the world
Pip Editable Installs • pip install -e <path to your
project> ◦ Installs a project by pointing to it ◦ Won’t work over pypi • Change your code, your installation reflects the changes • Super handy debugging tool • Fun way to explore other people’s projects!
Deploying Your Project To PyPI Step 1: Register for an
account
Deploying Your Project To PyPI Step 2: Create a .pypirc
in your home directory > cat .pypirc [server-login] username:Matt.Bachmann password:NotAChance
Deploying Your Project To PyPI Step 3: Register Your package
(from project root) > python setup.py register <Name>
Deploying Your Project To PyPI DONE!
Deploying Your Project To PyPI > pip install displayforecastio >
forecastio 42.3907 -71.1157 Currently: rain - Mixed precipitation tomorrow through Thursday, with temperatures falling to 42°F on Saturday.
Deploying Your Project To PyPI • Deploying Updates ◦ After
updating the version in setup.py > python setup.py sdist upload
References • Documentation ◦ https://readthedocs.org/ ◦ http://sphinx-doc.org/contents.html • Example Projects
◦ https://github.com/Bachmann1234/terminalweather ◦ https://github.com/pypa/sampleproject • Flake8 ◦ https://flake8.readthedocs.org/en/latest/ ◦ https://www.youtube.com/watch?v=wf-BqAjZb8M (Not about flake8 but an important lesson for anyone caring about style) • Folder Structure ◦ http://learnpythonthehardway.org/book/ex46.html • Licensing ◦ http://choosealicense.com/ • Pip ◦ http://pip.readthedocs.org/en/stable/user_guide/
References • PyPi ◦ https://pypi.python.org • reStructuredText ◦ http://docutils.sourceforge.net/ •
Setup.py ◦ https://docs.python.org/2/distutils/setupscript.html • Virtualenv ◦ http://virtualenv.readthedocs.org/en/latest/userguide.html