Everyday Project Packaging With pyproject.toml (Summary)
In this Code Conversation, you’ve learned that packaging is about more than just publishing a project on PyPI. In fact, it can be helpful for your own personal projects. You had the world of packaging demystified and got to know the new, officially sanctioned way of setting up your Python projects using a pyproject.toml
file and installing your package with pip
. With this, you get the following benefits:
- Being able to call your project from anywhere
- Playing on the same team as the import system
- Allowing for consistent imports
- Having one file that’ll work for many build systems
Along the way, you:
- Structured files and folders in your project
- Understood different ways to run your script
- Explored how the import system works
- Explored the Python packaging world
- Wrote a
pyproject.toml
file to configure your package - Installed your pacakge with
pip
Here are some further resources that you might find useful:
- Python import: Advanced Techniques and Tips
- How to Publish an Open-Source Python Package to PyPI
- How to Publish Your Own Python Package to PyPI - Video Course
- What Are Python Wheels and Why Should You Care?
Which of your projects will you package next? Share your ideas in the comments below!
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:01 Excellent. So basically, we’ve taken these two files that were not in any folder really, and we’ve taken it out and put it in a folder so that we can call it as modules.
00:13
And then we’ve taken that out again into a high-level project folder so that we could have a pyproject.toml
. That means we can build this package and have an editable install on our activated Python version. Again, we can do this with the global Python version if we want, but in this example, we did with a venv
. Yep. Great, so we can officially say this is the way to work. Yeah.
00:40
We mentioned briefly that it used to be setup.py
, setup.cfg
, and those things still work, but at some point, which is probably way into the future because all the legacy, they may stop, while pyproject.toml
is the way forward. Cool. Well, thank you for this walk-through of how to set up your project.
paulfwatts on Dec. 13, 2022
This is my first course as a paid subscriber.
I really enjoyed the conversational format and all the materials provided, plus the transcript, were excellent.
Nice to know there is a standard way to do this now!
paulfwatts on Dec. 13, 2022
This is my README.md added to my project file for this course, which may help others:
CourseEveryday Project Packaging With pyproject.toml (Overview) – Real Python
InstallationInstall the package in editable mode using -e
. This will install the package in development mode, so that any changes made to the source code will be reflected in the installed package. This is useful for development purposes. Run the following command in the root directory of the project (after creating and activating a virtual environment):
python -m pip install -e .
1. Building and Distributing Packages with Setuptools
2. Get to Know Python Packaging
3. Configuring setuptools using pyproject.toml files
4. Python and TOML: New Best Friends
wols on Dec. 24, 2022
The course should always be considered one of the first - a “way to work”.
Glenn Lehman on Dec. 30, 2022
I enjoyed this conversation! It helped to lay a solid foundation to my understanding of installing my own scripts. I did create an entire GitHub Repo to capture the code at the end of most videos.
Martin Breuss RP Team on Jan. 2, 2023
Nice, glad you enjoyed the conversation @Glenn Lehmann. You can also download the sample code from the Supporting Materials dropdown at the top of the page.
Although that code doesn’t include your detailed Video Time Index :D
sanvorav on April 12, 2023
Love this course!! 💚🐍 This course is ESSENTIAL for all doing any development work.
NOTE:
If you’re using a Poetry
environment, you can install using the command:
poetry add --editable ./myproject
This will add the line (below) to the
Poetry
pyproject.toml
file:
myproject = {path = "myproject", develop = true}
A
myproject.egg-info
folder will also be generated.
Pradeep Kumar on July 13, 2023
This was excellent. I like this content so much, it is much better than plain videos. Two people discussing new things and it is entertaining as well as enriching. I learned a lot.
Off topic question:
1) How did you made your Powershell prompt that way. Is there any tutorial that can be looked into?
2) I have also seen __init__.py
files in many places, what does that do in general?
ole088 on Dec. 2, 2023
Pradeep - You can use a PowerShell profile to change your prompt. For information on using profiles, see about Profiles. There is also a section that shows how to Add a customized prompt.
I also enjoyed this conversation. I found this format a little easier to “code-follow” than the other courses. Others sometimes go a little too fast, but I still find them all very useful.
MischaelR on Jan. 20, 2024
I really enjoyed this course. A lot of great information that isn’t included in standard learning paths.
makearney on April 21, 2024
Excellent course/conversation/tutorial. It answers many issues I have wrestled with regarding python project development since I started using python. Those were serious enough that I finally decided to solve the problem myself before embarking on any large scale project. The “best” solution I found was to bury the problem in a container, which was not a solution at all. I also encountered other solutions in various other states of completion.
This feels good.I was surprised to learn that all the bits required and presented were not fully accepted and implemented until python 12.x, just months ago. That’s ok. There is pile of development/implementation/suport that I don’t have to worry about now.
Hats off to everyone to who worked to achieve this! Have been there and didn’t really want to do it again. Phew!
Become a Member to join the conversation.
Diego de Pablos on Dec. 12, 2022
This was really helpful. It’s good to learn how to do these things once and for all!