SlideShare a Scribd company logo
STRUCTURING PYTHON PROJECTS
In practical terms, “structure” means:
making clean code whose logic and dependencies
are clear as well as how the files and folders are
organized in the filesystem.
What does structure means
Keep the root clean:
- General files like README, LICENSE, etc
- requirements.txt
- tests / (or test.py)
- doc/
- project_name/ (or project_name.py)
- setup.py
- Manage.py (Django)
- Other tooling like .gitignore, .circleci/ etc…
Principle for any repository
Things to avoid:
- Circular dependencies
- Hidden coupling
- Spaghetti
- Ravioli
Generic considerations:
- Separate concerns with decorators
- Use context manager when setup and teardown is needed
Principle for any repository
Structuring and packaging your python project
- Modules are Just .py files.
- __name__ == ‘__main__’ to be usable as scripts
- Modules are compiled into .pyc files
- Module names standards
- Each module is its own isolated world (namespace).
- Module execution
Modules - basics
- Search path
- from module import *
- from module import x
Modules - Imports
Structuring and packaging your python project
- Packages are folders that contain __init__ file
- What should __init__ file used for
- Executable submodule using __main__.py file
- Each package should be consumable from outside and
consumed by its “public” interface.
- Divide and conquer, divide huge project to small packages
(Import) Packages- basics
Structuring and packaging your python project
- Shareable/installable compiled package
- PyPI is public python package repository
- .pypirc for PyPI settings *.
(Distribution) Packages- basics
- Create distribution files
- Packaging and distribution manager
(Distribution) Packages-
Setup.py
- Installation developer mode by pip install –e
Structuring and packaging your python project
Structuring and packaging your python project
• Writing the Setup Script
• Structuring large python projects
• Packaging Python Projects
• Comprehensive Modules and Packages talk
• Installing Packages
Resources
Ad

More Related Content

Similar to Structuring and packaging your python project (20)

Odoo (Build module, Security, ORM)
Odoo (Build module, Security, ORM)Odoo (Build module, Security, ORM)
Odoo (Build module, Security, ORM)
sroo galal
 
Module Structure in Odoo 15
Module Structure in Odoo 15Module Structure in Odoo 15
Module Structure in Odoo 15
Celine George
 
Module Structure in Odoo 16
Module Structure in Odoo 16Module Structure in Odoo 16
Module Structure in Odoo 16
Celine George
 
Python libraries
Python librariesPython libraries
Python libraries
Prof. Dr. K. Adisesha
 
Modules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdfModules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdf
RavindraTambe3
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
roskakori
 
jb_Modules_in_Python.pptx jb_Modules_in_Python.pptx
jb_Modules_in_Python.pptx jb_Modules_in_Python.pptxjb_Modules_in_Python.pptx jb_Modules_in_Python.pptx
jb_Modules_in_Python.pptx jb_Modules_in_Python.pptx
paurushsinhad
 
Drupal Coding Standards - do and don't
Drupal Coding Standards - do and don'tDrupal Coding Standards - do and don't
Drupal Coding Standards - do and don't
Arunkumar Kupppuswamy
 
Modules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptxModules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptx
arunavamukherjee9999
 
mod.ppt mod.ppt mod.ppt mod.ppt mod.pp d
mod.ppt mod.ppt mod.ppt mod.ppt mod.pp dmod.ppt mod.ppt mod.ppt mod.ppt mod.pp d
mod.ppt mod.ppt mod.ppt mod.ppt mod.pp d
paurushsinhad
 
Demonstration module in Odoo 17 - Odoo 17 Slides
Demonstration module in Odoo 17 - Odoo 17 SlidesDemonstration module in Odoo 17 - Odoo 17 Slides
Demonstration module in Odoo 17 - Odoo 17 Slides
Celine George
 
How to Build a Module in Odoo 15 Scaffold Method
How to Build a Module in Odoo 15 Scaffold MethodHow to Build a Module in Odoo 15 Scaffold Method
How to Build a Module in Odoo 15 Scaffold Method
Celine George
 
Python modules
Python modulesPython modules
Python modules
Shanmugapriya Dineshbabu
 
Interesting Presentation on Python Modules and packages
Interesting Presentation on Python Modules and packagesInteresting Presentation on Python Modules and packages
Interesting Presentation on Python Modules and packages
arunavamukherjee9999
 
jb_Modules_in_Python.ppt
jb_Modules_in_Python.pptjb_Modules_in_Python.ppt
jb_Modules_in_Python.ppt
loliktry
 
Django
DjangoDjango
Django
Sayeed Far Ooqui
 
Yocto: Training in English
Yocto: Training in EnglishYocto: Training in English
Yocto: Training in English
Otavio Salvador
 
Django course summary
Django course summaryDjango course summary
Django course summary
Udi Bauman
 
fuelOrigin.docx
fuelOrigin.docxfuelOrigin.docx
fuelOrigin.docx
KanhaJi5
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
Haitham El-Ghareeb
 
Odoo (Build module, Security, ORM)
Odoo (Build module, Security, ORM)Odoo (Build module, Security, ORM)
Odoo (Build module, Security, ORM)
sroo galal
 
Module Structure in Odoo 15
Module Structure in Odoo 15Module Structure in Odoo 15
Module Structure in Odoo 15
Celine George
 
Module Structure in Odoo 16
Module Structure in Odoo 16Module Structure in Odoo 16
Module Structure in Odoo 16
Celine George
 
Modules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdfModules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdf
RavindraTambe3
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
roskakori
 
jb_Modules_in_Python.pptx jb_Modules_in_Python.pptx
jb_Modules_in_Python.pptx jb_Modules_in_Python.pptxjb_Modules_in_Python.pptx jb_Modules_in_Python.pptx
jb_Modules_in_Python.pptx jb_Modules_in_Python.pptx
paurushsinhad
 
Drupal Coding Standards - do and don't
Drupal Coding Standards - do and don'tDrupal Coding Standards - do and don't
Drupal Coding Standards - do and don't
Arunkumar Kupppuswamy
 
Modules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptxModules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptx
arunavamukherjee9999
 
mod.ppt mod.ppt mod.ppt mod.ppt mod.pp d
mod.ppt mod.ppt mod.ppt mod.ppt mod.pp dmod.ppt mod.ppt mod.ppt mod.ppt mod.pp d
mod.ppt mod.ppt mod.ppt mod.ppt mod.pp d
paurushsinhad
 
Demonstration module in Odoo 17 - Odoo 17 Slides
Demonstration module in Odoo 17 - Odoo 17 SlidesDemonstration module in Odoo 17 - Odoo 17 Slides
Demonstration module in Odoo 17 - Odoo 17 Slides
Celine George
 
How to Build a Module in Odoo 15 Scaffold Method
How to Build a Module in Odoo 15 Scaffold MethodHow to Build a Module in Odoo 15 Scaffold Method
How to Build a Module in Odoo 15 Scaffold Method
Celine George
 
Interesting Presentation on Python Modules and packages
Interesting Presentation on Python Modules and packagesInteresting Presentation on Python Modules and packages
Interesting Presentation on Python Modules and packages
arunavamukherjee9999
 
jb_Modules_in_Python.ppt
jb_Modules_in_Python.pptjb_Modules_in_Python.ppt
jb_Modules_in_Python.ppt
loliktry
 
Yocto: Training in English
Yocto: Training in EnglishYocto: Training in English
Yocto: Training in English
Otavio Salvador
 
Django course summary
Django course summaryDjango course summary
Django course summary
Udi Bauman
 
fuelOrigin.docx
fuelOrigin.docxfuelOrigin.docx
fuelOrigin.docx
KanhaJi5
 

More from Eyal Trabelsi (6)

Getting to know any dataset
Getting to know any datasetGetting to know any dataset
Getting to know any dataset
Eyal Trabelsi
 
Make Terminal Fun Again
Make Terminal Fun AgainMake Terminal Fun Again
Make Terminal Fun Again
Eyal Trabelsi
 
Advance sql session - strings
Advance sql  session - stringsAdvance sql  session - strings
Advance sql session - strings
Eyal Trabelsi
 
Bring sanity back to sql (advance sql)
Bring sanity back to sql (advance sql)Bring sanity back to sql (advance sql)
Bring sanity back to sql (advance sql)
Eyal Trabelsi
 
Advance sql - window functions patterns and tricks
Advance sql - window functions patterns and tricksAdvance sql - window functions patterns and tricks
Advance sql - window functions patterns and tricks
Eyal Trabelsi
 
Seminar - Similarity Joins in SQL (performance and semantic joins)
Seminar - Similarity Joins in SQL (performance and semantic joins)Seminar - Similarity Joins in SQL (performance and semantic joins)
Seminar - Similarity Joins in SQL (performance and semantic joins)
Eyal Trabelsi
 
Getting to know any dataset
Getting to know any datasetGetting to know any dataset
Getting to know any dataset
Eyal Trabelsi
 
Make Terminal Fun Again
Make Terminal Fun AgainMake Terminal Fun Again
Make Terminal Fun Again
Eyal Trabelsi
 
Advance sql session - strings
Advance sql  session - stringsAdvance sql  session - strings
Advance sql session - strings
Eyal Trabelsi
 
Bring sanity back to sql (advance sql)
Bring sanity back to sql (advance sql)Bring sanity back to sql (advance sql)
Bring sanity back to sql (advance sql)
Eyal Trabelsi
 
Advance sql - window functions patterns and tricks
Advance sql - window functions patterns and tricksAdvance sql - window functions patterns and tricks
Advance sql - window functions patterns and tricks
Eyal Trabelsi
 
Seminar - Similarity Joins in SQL (performance and semantic joins)
Seminar - Similarity Joins in SQL (performance and semantic joins)Seminar - Similarity Joins in SQL (performance and semantic joins)
Seminar - Similarity Joins in SQL (performance and semantic joins)
Eyal Trabelsi
 
Ad

Recently uploaded (20)

Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
CSUC - Consorci de Serveis Universitaris de Catalunya
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Top-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptxTop-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptx
BR Softech
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
Top-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptxTop-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptx
BR Softech
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Ad

Structuring and packaging your python project

  • 2. In practical terms, “structure” means: making clean code whose logic and dependencies are clear as well as how the files and folders are organized in the filesystem. What does structure means
  • 3. Keep the root clean: - General files like README, LICENSE, etc - requirements.txt - tests / (or test.py) - doc/ - project_name/ (or project_name.py) - setup.py - Manage.py (Django) - Other tooling like .gitignore, .circleci/ etc… Principle for any repository
  • 4. Things to avoid: - Circular dependencies - Hidden coupling - Spaghetti - Ravioli Generic considerations: - Separate concerns with decorators - Use context manager when setup and teardown is needed Principle for any repository
  • 6. - Modules are Just .py files. - __name__ == ‘__main__’ to be usable as scripts - Modules are compiled into .pyc files - Module names standards - Each module is its own isolated world (namespace). - Module execution Modules - basics
  • 7. - Search path - from module import * - from module import x Modules - Imports
  • 9. - Packages are folders that contain __init__ file - What should __init__ file used for - Executable submodule using __main__.py file - Each package should be consumable from outside and consumed by its “public” interface. - Divide and conquer, divide huge project to small packages (Import) Packages- basics
  • 11. - Shareable/installable compiled package - PyPI is public python package repository - .pypirc for PyPI settings *. (Distribution) Packages- basics - Create distribution files
  • 12. - Packaging and distribution manager (Distribution) Packages- Setup.py - Installation developer mode by pip install –e
  • 15. • Writing the Setup Script • Structuring large python projects • Packaging Python Projects • Comprehensive Modules and Packages talk • Installing Packages Resources

Editor's Notes

  • #4: A pip requirements file should be placed at the root of the repository. It should specify the dependencies required to contribute to the project: testing, building, and generating documentation. If your project has no development dependencies, or you prefer development environment setup via setup.py, this file may be unnecessary.
  • #5: Matplotlib for example for state Spaghetti long functions Ravioli too short with 100 of classes
  • #7: Module name - keep module names short, lowercase, and be sure to avoid using special symbols like the dot (.) - or question mark (?). Module execution - when a module is imported all statement execute until end of file reached the content of module namespace are all of the global names that still defined at the end of the execution process
  • #8: Search path – if a file is not on the path it wont import sys.path sometimes you might hack it by sys.path.append From module import * – take all symbols from a module and place them into local scope (__all__) From module import x – allows parts of the module to be used without having to type the module prefix lifts selected symbols out of a module after import it ! And make it available locally
  • #10: Init file can be used as façade to combine multiple modules a simple init file is good one (no initialization or monkey patching even not logs) We can do it without __init__.py but than weird namespace black magic occur namespace packaegs Main file explicitly marks the entry point
  • #12: You might require wheel twhine and tox to interable with pypi
  • #13: Source distribution vs built distribution - Hold Meta information of your package Hold executable to complete your packing tasks Uploading it to pypi or artifactory Setup.py also has: -classifier where your package can be used for search - Install_requires for requirements - find_p[ackages to find packages - Entry points console scripts
  • #16: Decorator example cache
  翻译: