|
| https://realpython.com/ |
| Start Here | https://realpython.com/start-here/ |
|
Learn Python
| https://realpython.com/lessons/structuring-python-application-summary/ |
| Python Tutorials →In-depth articles and video courses | https://realpython.com/search?kind=article&kind=course&order=newest |
| Learning Paths →Guided study plans for accelerated learning | https://realpython.com/learning-paths/ |
| Quizzes & Exercises →Check your learning progress | https://realpython.com/quizzes/ |
| Browse Topics →Focus on a specific area or skill level | https://realpython.com/tutorials/all/ |
| Community Chat →Learn with other Pythonistas | https://realpython.com/community/ |
| Office Hours →Live Q&A calls with Python experts | https://realpython.com/office-hours/ |
| Podcast →Hear what’s new in the world of Python | https://realpython.com/podcasts/rpp/ |
| Books →Round out your knowledge and learn offline | https://realpython.com/products/books/ |
| Reference →Concise definitions for common Python terms | https://realpython.com/ref/ |
| Code Mentor →BetaPersonalized code assistance & learning tools | https://realpython.com/mentor/ |
| Unlock All Content → | https://realpython.com/account/join/ |
|
More
| https://realpython.com/lessons/structuring-python-application-summary/ |
| Learner Stories | https://realpython.com/learner-stories/ |
| Python Newsletter | https://realpython.com/newsletter/ |
| Python Job Board | https://www.pythonjobshq.com |
| Meet the Team | https://realpython.com/team/ |
| Become a Tutorial Writer | https://realpython.com/write-for-us/ |
| Become a Video Instructor | https://realpython.com/become-an-instructor/ |
| Search | https://realpython.com/search |
| https://realpython.com/search |
| Join | https://realpython.com/account/join/ |
| Sign‑In | https://realpython.com/account/login/?next=%2Flessons%2Fstructuring-python-application-summary%2F |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson&utm_content=structuring-python-application |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson&utm_content=structuring-python-application |
| https://realpython.com/courses/structuring-python-application/#team |
| Structuring a Python Application | https://realpython.com/courses/structuring-python-application/ |
| Christopher Trudeau | https://realpython.com/courses/structuring-python-application/#team |
| Recommended Tutorial | https://realpython.com/python-application-layouts/ |
| Course Slides (.pdf) | https://realpython.com/courses/structuring-python-application/downloads/layout-slides/ |
| Sample Code (.zip) | https://realpython.com/courses/structuring-python-application/downloads/layout-code/ |
| Ask a Question | https://realpython.com/lessons/structuring-python-application-summary/#discussion |
| https://realpython.com/feedback/survey/course/structuring-python-application/liked/?from=lesson-title |
| https://realpython.com/feedback/survey/course/structuring-python-application/disliked/?from=lesson-title |
| Contents | https://realpython.com/lessons/structuring-python-application-summary/#description |
| Transcript | https://realpython.com/lessons/structuring-python-application-summary/#transcript |
| Discussion (14) | https://realpython.com/lessons/structuring-python-application-summary/#discussion |
| Sample Code (.zip) | https://realpython.com/courses/structuring-python-application/downloads/layout-code/ |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson_preview&utm_content=structuring-python-application |
| Sign-In | https://realpython.com/account/login/ |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson_preview&utm_content=structuring-python-application |
| Sign-In | https://realpython.com/account/login/ |
| 00:00 | https://realpython.com/lessons/structuring-python-application-summary/#t=0.48 |
| This series of videos has talked about the file structure for your Python | https://realpython.com/lessons/structuring-python-application-summary/#t=0.48 |
| applications. | https://realpython.com/lessons/structuring-python-application-summary/#t=3.84 |
| I started off by showing you a single-file program and associated configuration | https://realpython.com/lessons/structuring-python-application-summary/#t=5.16 |
| files, moved up to larger applications that used modules, | https://realpython.com/lessons/structuring-python-application-summary/#t=9.24 |
| and then went to larger applications still that used multiple modules. | https://realpython.com/lessons/structuring-python-application-summary/#t=12.99 |
| 00:17 | https://realpython.com/lessons/structuring-python-application-summary/#t=17.55 |
| Then, I showed you the differences in structures for web frameworks | https://realpython.com/lessons/structuring-python-application-summary/#t=17.55 |
| such as Django and Flask. In this lesson, | https://realpython.com/lessons/structuring-python-application-summary/#t=20.7 |
| I’m going to wrap up and then show you some variations. | https://realpython.com/lessons/structuring-python-application-summary/#t=23.4 |
| 00:26 | https://realpython.com/lessons/structuring-python-application-summary/#t=26.43 |
| As I mentioned in the first lesson, | https://realpython.com/lessons/structuring-python-application-summary/#t=26.43 |
| this video is based on an article by one of my colleagues at Real | https://realpython.com/lessons/structuring-python-application-summary/#t=28.2 |
| Python named Kyle. As a result of this, | https://realpython.com/lessons/structuring-python-application-summary/#t=31.14 |
| I’ve been able to see the comments attached to the article so I can possibly | https://realpython.com/lessons/structuring-python-application-summary/#t=33.81 |
| anticipate some of your questions. Python really | https://realpython.com/lessons/structuring-python-application-summary/#t=37.23 |
| isn’t opinionated about file structure. As a result, | https://realpython.com/lessons/structuring-python-application-summary/#t=40.35 |
| there’s a lot of variation out there. | https://realpython.com/lessons/structuring-python-application-summary/#t=43.17 |
| 00:45 | https://realpython.com/lessons/structuring-python-application-summary/#t=45.72 |
| Desktop applications have their own intricacies. | https://realpython.com/lessons/structuring-python-application-summary/#t=45.72 |
| If you’re doing Tk or Qt, | https://realpython.com/lessons/structuring-python-application-summary/#t=48.99 |
| they both require to have modules structured in a certain way, | https://realpython.com/lessons/structuring-python-application-summary/#t=51.9 |
| and that will impact the layout. Packaging has never been Python’s strength; | https://realpython.com/lessons/structuring-python-application-summary/#t=55.14 |
| it’s always been handled through third-party libraries rather than in the | https://realpython.com/lessons/structuring-python-application-summary/#t=59.4 |
| built-in ones. | https://realpython.com/lessons/structuring-python-application-summary/#t=62.4 |
| 01:03 | https://realpython.com/lessons/structuring-python-application-summary/#t=63.93 |
| That means there’s been lots of opinions and lots of change over the years. | https://realpython.com/lessons/structuring-python-application-summary/#t=63.93 |
| There are currently a half dozen popular virtual env management tools out there, | https://realpython.com/lessons/structuring-python-application-summary/#t=68.82 |
| so I don’t expect this is going to stay static. | https://realpython.com/lessons/structuring-python-application-summary/#t=73.26 |
| 01:16 | https://realpython.com/lessons/structuring-python-application-summary/#t=76.11 |
| It’s going to keep changing. Online, | https://realpython.com/lessons/structuring-python-application-summary/#t=76.11 |
| there’s currently a bit of a debate about whether or not you should put your | https://realpython.com/lessons/structuring-python-application-summary/#t=78.69 |
| Python source code inside of an src/ directory. | https://realpython.com/lessons/structuring-python-application-summary/#t=81.69 |
| 01:25 | https://realpython.com/lessons/structuring-python-application-summary/#t=85.05 |
| There’s pros and cons to this. | https://realpython.com/lessons/structuring-python-application-summary/#t=85.05 |
| The current directory that you’re in is sys.path. | https://realpython.com/lessons/structuring-python-application-summary/#t=86.88 |
| This makes it really easy to import something in a simple script, | https://realpython.com/lessons/structuring-python-application-summary/#t=89.76 |
| but it also makes it easy to make mistakes when you’re packaging. | https://realpython.com/lessons/structuring-python-application-summary/#t=93.15 |
| 01:36 | https://realpython.com/lessons/structuring-python-application-summary/#t=96.87 |
| Putting things inside of a src/ (source) directory forces you to test the installment | https://realpython.com/lessons/structuring-python-application-summary/#t=96.87 |
| and make sure that pieces are working properly. Unfortunately, | https://realpython.com/lessons/structuring-python-application-summary/#t=100.5 |
| some IDEs have problems with this structure, | https://realpython.com/lessons/structuring-python-application-summary/#t=103.95 |
| so it can make your life a little more complicated depending on what tools | https://realpython.com/lessons/structuring-python-application-summary/#t=106.14 |
| you’re using. And, the Python packaging authority does not currently use this | https://realpython.com/lessons/structuring-python-application-summary/#t=109.32 |
| mechanism. The debate rages on though. Throughout the lessons, | https://realpython.com/lessons/structuring-python-application-summary/#t=113.1 |
| you’ve seen me using setup.py. In addition to setup.py, there’s something | https://realpython.com/lessons/structuring-python-application-summary/#t=117.33 |
| called setup.cfg. setup.py | https://realpython.com/lessons/structuring-python-application-summary/#t=121.38 |
| is an actual Python program—setup.cfg is just a data file. | https://realpython.com/lessons/structuring-python-application-summary/#t=123.96 |
| 02:08 | https://realpython.com/lessons/structuring-python-application-summary/#t=128.94 |
| You can specify a lot of the same type of configuration in a CFG file | https://realpython.com/lessons/structuring-python-application-summary/#t=128.94 |
| as you can inside of setup.py. The file format uses an INI style declaration | https://realpython.com/lessons/structuring-python-application-summary/#t=132.57 |
| and it’s an easier way of providing defaults, | https://realpython.com/lessons/structuring-python-application-summary/#t=137.82 |
| so if your installer of choice wants to be able to give the person doing the | https://realpython.com/lessons/structuring-python-application-summary/#t=140.13 |
| installation some choices, | https://realpython.com/lessons/structuring-python-application-summary/#t=144.36 |
| using a text file to provide those choices and then allowing them to be | https://realpython.com/lessons/structuring-python-application-summary/#t=146.85 |
| overwritten is easier. And although CFG is supported, | https://realpython.com/lessons/structuring-python-application-summary/#t=150.69 |
| it doesn’t seem to be as popular as setup.py, | https://realpython.com/lessons/structuring-python-application-summary/#t=154.92 |
| but that might just be because I tend to spend a lot of my time looking at older | https://realpython.com/lessons/structuring-python-application-summary/#t=157.47 |
| code. Another variation is where to put the tests/ folder. | https://realpython.com/lessons/structuring-python-application-summary/#t=160.59 |
| 02:44 | https://realpython.com/lessons/structuring-python-application-summary/#t=164.55 |
| Some programmers prefer to put this inside of the module directory instead of | https://realpython.com/lessons/structuring-python-application-summary/#t=164.55 |
| the project route. This works fine enough. | https://realpython.com/lessons/structuring-python-application-summary/#t=168.09 |
| If you don’t want to include your tests inside of your package object, | https://realpython.com/lessons/structuring-python-application-summary/#t=171.51 |
| it means you have to update your manifest files in order to make sure that they | https://realpython.com/lessons/structuring-python-application-summary/#t=174.66 |
| don’t get bundled. | https://realpython.com/lessons/structuring-python-application-summary/#t=177.75 |
| 02:59 | https://realpython.com/lessons/structuring-python-application-summary/#t=179.11 |
| One of the reasons to put it inside of your module files is to have your unit | https://realpython.com/lessons/structuring-python-application-summary/#t=179.11 |
| tests in with the modules, and then if you have separate integration tests, | https://realpython.com/lessons/structuring-python-application-summary/#t=182.71 |
| have that out at the project directory. | https://realpython.com/lessons/structuring-python-application-summary/#t=186.04 |
| 03:08 | https://realpython.com/lessons/structuring-python-application-summary/#t=188.2 |
| You’ll see some of these variations out there as you go through other people’s | https://realpython.com/lessons/structuring-python-application-summary/#t=188.2 |
| code. What about the virtual environment? Where should you put it? Well, | https://realpython.com/lessons/structuring-python-application-summary/#t=191.23 |
| the short answer is: it kind of depends. This is mostly a personal preference, | https://realpython.com/lessons/structuring-python-application-summary/#t=195.37 |
| but the tools that you’re using may have different expectations. | https://realpython.com/lessons/structuring-python-application-summary/#t=199.48 |
| 03:23 | https://realpython.com/lessons/structuring-python-application-summary/#t=203.38 |
| The Real Python Pipenv guide talks about virtual environments and how to | https://realpython.com/lessons/structuring-python-application-summary/#t=203.38 |
| create them and how to use them, if you’re looking for more information. | https://realpython.com/lessons/structuring-python-application-summary/#t=206.74 |
| 03:31 | https://realpython.com/lessons/structuring-python-application-summary/#t=211.03 |
| One of the reasons to stick with fairly standard file structures is it makes it | https://realpython.com/lessons/structuring-python-application-summary/#t=211.03 |
| easier for you | https://realpython.com/lessons/structuring-python-application-summary/#t=214.3 |
| to use tools out there that have expectations. tox is used for testing your | https://realpython.com/lessons/structuring-python-application-summary/#t=214.79 |
| program against multiple versions of Python and has expectations about your file | https://realpython.com/lessons/structuring-python-application-summary/#t=219.37 |
| structure and setup.py. twine is for uploading your package to pypi.org, | https://realpython.com/lessons/structuring-python-application-summary/#t=223.33 |
| if you’re sharing it, and it expects the distribution wheel created by setup.py. | https://realpython.com/lessons/structuring-python-application-summary/#t=228.07 |
| 03:52 | https://realpython.com/lessons/structuring-python-application-summary/#t=232.44 |
| For large programs, | https://realpython.com/lessons/structuring-python-application-summary/#t=232.44 |
| it’s usually helpful to do a little bit of linting and formatting. | https://realpython.com/lessons/structuring-python-application-summary/#t=234.58 |
| There’s plenty of choice for linters and checkers out there: pyflakes, | https://realpython.com/lessons/structuring-python-application-summary/#t=237.37 |
| pylink, pychecker, pep8, and flake8 are all very good tools. | https://realpython.com/lessons/structuring-python-application-summary/#t=240.58 |
| 04:05 | https://realpython.com/lessons/structuring-python-application-summary/#t=245.08 |
| Something that’s become popular in the last little while is a tool called black. | https://realpython.com/lessons/structuring-python-application-summary/#t=245.08 |
| It reformats your Python code. Generally, | https://realpython.com/lessons/structuring-python-application-summary/#t=248.59 |
| this stops your teams from fighting over what code should look like. | https://realpython.com/lessons/structuring-python-application-summary/#t=251.8 |
| 04:16 | https://realpython.com/lessons/structuring-python-application-summary/#t=256.18 |
| Typically, the result is no one’s happy about what the code looks like, | https://realpython.com/lessons/structuring-python-application-summary/#t=256.18 |
| and that’s sort of the sign of a good compromise. | https://realpython.com/lessons/structuring-python-application-summary/#t=259.39 |
| There are also good tools out there to help you bootstrap your programs | https://realpython.com/lessons/structuring-python-application-summary/#t=262.21 |
| using scaffolding technology. Two common ones are pyscaffold | https://realpython.com/lessons/structuring-python-application-summary/#t=265.3 |
| and cookiecutter. That’s everything I wanted to say. | https://realpython.com/lessons/structuring-python-application-summary/#t=269.2 |
| 04:32 | https://realpython.com/lessons/structuring-python-application-summary/#t=272.59 |
| Hopefully, the content’s been useful for you. Thank you for your attention. | https://realpython.com/lessons/structuring-python-application-summary/#t=272.59 |
| April 30, 2020 | https://realpython.com/lessons/structuring-python-application-summary/#comment-0f6eff03-10eb-46d5-94db-55e8658a723a |
| realpython.com/pipenv-guide | https://realpython.com/pipenv-guide |
| pyscaffold.org | https://pyscaffold.org |
| cookiecutter.readthedocs.io | https://cookiecutter.readthedocs.io |
| April 30, 2020 | https://realpython.com/lessons/structuring-python-application-summary/#comment-4941f505-ff68-4799-864e-41b7d91ba316 |
| May 1, 2020 | https://realpython.com/lessons/structuring-python-application-summary/#comment-b66f5c67-e50e-4b1d-898b-1bcf26e31b39 |
| May 14, 2020 | https://realpython.com/lessons/structuring-python-application-summary/#comment-ef5e6107-27e4-4f22-af53-6594aaf2d6af |
| June 16, 2020 | https://realpython.com/lessons/structuring-python-application-summary/#comment-226621aa-7981-488a-83c9-4c7a39352beb |
| Aug. 10, 2020 | https://realpython.com/lessons/structuring-python-application-summary/#comment-0f1b73da-0032-4a36-8e57-c559de8ae687 |
| Aug. 10, 2020 | https://realpython.com/lessons/structuring-python-application-summary/#comment-f6756149-9eec-4f30-8ed1-bfda5e46d1dd |
| Oct. 9, 2020 | https://realpython.com/lessons/structuring-python-application-summary/#comment-146f4020-cb2b-47f6-a0f0-ec7b5feef7ce |
| Jan. 12, 2022 | https://realpython.com/lessons/structuring-python-application-summary/#comment-a1d8f04c-50f9-429d-9590-f483fdc34bb5 |
| May 16, 2022 | https://realpython.com/lessons/structuring-python-application-summary/#comment-283bba8d-47c4-464f-95d7-dbbed7982a1d |
| April 12, 2023 | https://realpython.com/lessons/structuring-python-application-summary/#comment-696037ca-ad47-48da-937c-1a0cc0ab6aeb |
| April 13, 2023 | https://realpython.com/lessons/structuring-python-application-summary/#comment-097a3123-943d-4b23-ac26-3db52901c258 |
| Aug. 21, 2025 | https://realpython.com/lessons/structuring-python-application-summary/#comment-29b2d037-5c10-4e9a-aa6b-7570e248352d |
| Aug. 21, 2025 | https://realpython.com/lessons/structuring-python-application-summary/#comment-ad52e898-e985-4ea5-b821-332433441f79 |
| Become a Member | https://realpython.com/account/join/ |
| https://realpython.com/lessons/flask-web-application/ |
| Overview | https://realpython.com/courses/structuring-python-application/ |
|
Structuring a Python Application (Overview) 12:25
| https://realpython.com/videos/structuring-python-application/ |
|
Installable Single Package 06:11
| https://realpython.com/lessons/installable-single-package/ |
|
Application With Internal Packages 06:23
| https://realpython.com/lessons/application-internal-packages/ |
|
Django Web Application 04:19
| https://realpython.com/lessons/django-web-application/ |
|
Flask Web Application 01:58
| https://realpython.com/lessons/flask-web-application/ |
|
Structuring a Python Application (Summary) 04:39
| https://realpython.com/lessons/structuring-python-application-summary/ |
| Privacy Policy | https://realpython.com/privacy-policy/ |
Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover