Python Day #10: From Functions to Frameworks - How to Structure Clean, Reusable Python Code
Learn how to organize your Python code with modules, use built-in libraries, and install external packages to build clean, efficient, and professional-grade projects.
Your goal as you grow in your career as a developer is to write clean, readable, and reusable code. Code that can be used and understood by others.
In the last few lessons, you’ve been gaining a deep understanding of how to create and structure your own reusable code. We started with defining functions, little code blocks.
Last lesson, you were then introduced to creating your own Python modules. A Module is essentially a python .py
file that stores variables, functions and/or classes which can be imported and used in other parts of your code.
Python is incredible as firstly it is easier to understand the syntax and get going. But then secondly there are countless extensions, which we call libraries that we can import and use to build out and complete specific tasks.
Welcome back to the Python Roadmap to Success, where I am giving all my readers a fair chance at learning Python the right way, following a proven roadmap that I’ve structured and taught for over the last four years.
In this lesson, we will look at ways to strengthen your understanding of Python modules and start working with external Python libraries to enhance your code.
Every week you’ll be introduced to a new topic in Python, think of this as a mini starter course to get you going and allow you to have a structured roadmap that actually builds to create you a solid foundation in Python. Join us today!
You now know all about writing and creating your own modules. They allow us to split off and structure our code throughout various python files to help keep everything organized and well maintained, especially as your programs and applications grow.
Over the last 8+ years I’ve been teaching full-time around the world which has given me the unique opportunity to work with over 1,500+ students. The last four years I’ve been teaching Python full-time. Breaking down complex topics, step by step.
I’ve spent this time curating a structured learning path that ensures my students have the greatest chance of success and don’t just learn but actually master Python as well as their logical thinking and problem solving.
In this article, we’re going to build on what you’ve already learned with creating modules, while now expanding your skillset to work with built-in modules. Last time, you worked on writing your own modules. Now, it’s time to practice and build on that. The goal is to now start using other modules that have already been made for us.
One point I should note is, spend time digesting these when I write them, after six weeks most of my posts are automatically put behind a paywall.
If you haven’t subscribed to my premium content yet, you should definitely check it out. You unlock exclusive access to all of these articles and all the code that comes with them, so you can follow along!
Plus, you’ll get access to so much more, like monthly Python projects, in-depth weekly articles, the '3 Randoms' series, and my complete archive!
I spend a lot of my week on these articles, so if you find it valuable, consider joining premium. It really helps me keep going and lets me know you’re getting something out of my work!
Thank you for allowing me to do work that I find meaningful. This is my full-time job so I hope you will support my work by joining as a premium reader today.
👉 Only for one more week, I am offering my readers a 30% off on all annual subscriptions! Kick off the summer season the right way!
If you’re already a premium reader, thank you from the bottom of my heart! You can leave feedback and recommend topics and projects at the bottom of all my articles.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
P.S - Drop any questions in the comments or feel free to DM me directly as I’m always happy to help you guys out.
What is a Module?
Last lesson, you were introduced on how to create and write your own module. We talked about why and how we do this to better improve our code. I always begin by teaching you to write out your own modules first as this leads nicely into this part.
Quick recap, instead of creating only one python .py
file, you can create as many as you want as long as they are in the same directory. This would mean that you have your standard main.py
file, then you may have another file called, calc.py
for example, this could be called anything though.
As of now, these are two completely unrelated files. The main.py
file will be the main file, this is the only real file you will run. This file will then automatically call and utilize other code from other python files, so you don’t need to run every file.
Then our calc.py
file could store all the functions we have written. If we image we have some functions for handling mathematical calculations, we could store them all here.
In order to use them we need to give the main.py
file access to the functions, and call those functions in our main.py
file. This keeps the main file clean and easy to read without also have to store the entire function definition.
We begin with learning how to creating our own modules as you have learned how to define your own functions, that leads into storing functions into modules, easy peasy.
Since you’ve wrapped your head around modules and functions we can now start to work with some of the many Python libraries out there.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
Modules, Libraries, and Frameworks
You will now start to hear these terms more and more so we should cover what they are and the differences. You know what a module is, it’s a single Python file that stores reusable pre-built Python functions.
The step up from that I’d call a library. A library stores more than one module, there may be five or so modules in a library, each module is a piece of the greater library but each module also serves a specific purpose as well.
Then finally we have a framework. This is a much more comprehensive structure that provides the overall architecture and control flow for building an application, often using different libraries and other components.
As you start writing your own software and applications there is a good chance you will use all of these. Sometimes you will use them individually, while other times you will actually use them all in a single application.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
Ready to Take Your First Steps with Python?
Most people get stuck before they even start. But you don’t have to!
I’ve put together a Free Course: The Pure Basics of Python that covers the very basics of Python, made just for beginners like you.
👉 I’m giving you my exact system that’s been proven and tested by over 1,500 students over the last 4+ years!
Here’s what you’ll learn:
✅ Step-by-step help to set up VS Code and install Python.
✅ Learn how to use variables, built-in functions, and even nesting functions.
✅ A quick test to see how much you’ve picked up.
✅ My handcrafted Python Guide to keep you on track.
This free course is a perfect first step — you’ll get a feel for my teaching style and build confidence to keep going.
👉 Ready to get started?
P.S. — If you like the free course (and I think you will!), I’ll show you how to dive deeper with my full Python Masterclass.
🎁 - Get a free one-on-one coaching session with any Masterclass!
Go through the entire Masterclass, complete all material, and attend the Q&A's, if you still feel like your struggling I'll personally work with you one-on-one until you're confident!
Starter Modules to Use Today
I’ll be honest, I am not sure how many modules/python has to offer. If I throw a number out there like 100,000, that is still a rough estimate of the number of libraries. According to google search there are 137,000 but this changes a lot and it’s tough to say.
So firstly, that is insane! This is also a reason why Python so so amazing, the real power behind Python lies in its readability and the number of modules. We will start working with more advanced modules but for today since we are still learning I will touch on just a few common and simple modules so you can get working with them.
I want you to see how we use preexisting code in our applications while also being able to merge to create our own modules. Here are some easy ones you can use today that you can implement in your programs to practice and expand their use cases.
I have put these in the order that you should learn and try these out. They start real easy and build, nothing too challenging but all of them incredibly useful as you progress in your careers. These are only four but they will give you a good start.
random
– Random Number Generation
The random
module is used when your code needs to make decisions based on chance, simulate randomness, or create randomized outputs. It’s great for things like shuffling cards, picking a random item from a list, generating random numbers for simulations or games, or even for basic testing scenarios.
Use it when building simple games, simulations, or when introducing any level of uncertainty or variation in your program. Module instructions are here.
math
– Mathematical Functions
The math
module gives you access to advanced mathematical functions that go beyond basic arithmetic. It includes tools like square roots, trigonometric functions, logarithms, and constants like pi and e.
You use math
when writing code that involves more precise or scientific calculations—like in physics simulations, engineering applications, or when building algorithms that require accurate computation, such as machine learning or geometry-based apps. Module instructions are here.
time
– Time and Delays
The time
module is nice when your program needs to deal with timing—whether it’s pausing execution, measuring how long something takes, or working with timestamps.
You’d use it when you need to delay a function (time.sleep()
), measure performance, or log when events happen. It’s helpful in automation scripts, scheduling tasks, animations, or tracking how long a process takes to run. Module instructions are here.
os
– Operating System Interface
The os
module is used when you want your Python program to interact with the operating system—like working with files, folders, and environment variables. You’ll use it when you need to create or delete directories, read or write files, change file paths, or run terminal commands from within your code.
For example, if you’re building a script that processes all .csv
files in a folder or needs to access file paths across different platforms (Windows, macOS, Linux), os
helps handle those tasks in a cross-platform way. Module instructions are here.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
External Python Libraries
All the above are considered built-in Python modules. This means that they actually come with Python so there is no need for any additional installation, you do need to import them at the top of your code but then you are good to go.
We have built-in modules for: General Utility, Data Handling, Debugging, Network, Testing, etc. There are a lot so you can see them here.
Now I won’t go into too much detail as once you pick up the built in modules this comes in naturally and we will use these later in our Python Roadmap to Success series but most of those 137,000+ modules are what we call external libraries.
This means that they are not built-in to Python. They have been created by other developers and companies to achieve unique tasks. Everything from Data Analytics, Machine Learning to GUI Development and Databases.
Most of the modules you will come across are these external libraries. In order to use them you need to install them on your system. Ideally you should set up what’s called a virtual environment which I will actually discuss in the next lesson.
But as a beginner you can get started with them just on your local system. To install an external library you need to use pip, which stand for Python Install Package as we run this in our terminal.
As an example I will use: pandas. This is the most popular data analytics library used in data science. This example will work for any library so just swap out pandas with the one you’d like to import.
Two options to import depending on your system. The most common is the simple pip command, so for instance you’d open your terminal and run the following:
pip install pandas
This here would get the external library on your system so you could import it and use it as normal. Start with this command, you may run pip or pip3 install. Try these first.
No many of my students work on Windows so sometimes this doesn’t actually work or you are thrown some installation error. This is frustrating, if the first option doesn’t work for you then you can try the command below.
python -m pip install pandas
This should overwrite it and make sure that you get the package on your computer. Now with anything I can not emphasize this enough. Read the documentation for the library.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
R.T.F.M
Years ago I had a mentor named Manu in the dive industry and I will never forget this. A colleague asked Manu how to set up his new dive computer. The response from Manu was simple, he said “RTFM”.
Read The F*cking Manual
It was that simple. Documentation is so important. Documentation is literally instructions on how something works and how to use it. Everything in software has documentation.
Therefore every library and module has in-depth documentation that gets you started from importing the library all the way to breaking down and showing you how to use every single functionality of the library.
Reading and understanding documentation is a skill, but this is one of the most powerful skills as a developer. Take an hour, get on the documentation and read. Read through it and follow along. If you can follow instructions, then you can do this.
Here is the documentation to pandas as an example. You don’t have to read much of this but you can read over it to get a feel for how docs look. Pandas docs here.
My Best Starter Resources
Here are the best resources I have to offer to get you started with Python no matter your background! Check these out as they’re bound to maximize your growth in the field.
Code with Josh: This is my YouTube channel where I post videos every week designed to help break things down and help you grow.
Zero to Knowing: My Python Masterclass platform designed from 8 years teaching experience and that has helped over 1,500+ students succeed with Python. (All my readers unlock a limited time, 35% discount, use code: pythonsummer35)
My Books: Maybe you’re looking to get a bit more advanced in Python. I’ve written 3 books to help with that, from Data Analytics, to SQL all the way to Machine Learning.
The Nerd Nook: This is where you are right now! I write here multiple times per week with the sole goal of breaking down this larger than life topic to help you excel and learn Python faster than you thought was possible.
This article will be a piece to a larger roadmap but will go behind a paywall after 6 weeks! To help support my work in teaching others consider joining as a premium reader to unlock all these articles, monthly Python projects and in-depth dives.
Wrapping Up Lesson Ten
You’ve come a long way. You started by learning how to write your own functions and modules, and now you’re beginning to understand how to use all the built-in and external tools that Python has to offer.
This is the part where things really start to open up. You’re not just writing everything from scratch anymore—you’re learning how to build smarter and faster by using tools that other people have already created.
The real goal isn’t just to make things work. It’s to write code that’s clean, easy to read, and easy to reuse—code that someone else can look at and understand without getting lost. That’s what good developers do.
And by learning how to organize your code with modules and use what’s already built into Python, you’re setting yourself up for success when you move on to bigger projects.
Thanks for sticking with me and putting in the time to learn. If this lesson helped you out, feel free to share it with someone else who’s learning too. And if you want to support what I’m doing here, consider joining the premium membership. That’s what keeps this going and lets me keep making useful content like this every week.
Don’t forget: R.T.F.M
Let’s keep moving forward with Day #11 next week.
Hope you all have an amazing week nerds ~ Josh (Chief Nerd Officer 🤓)
👉 If you’ve been enjoying these lessons, consider subscribing to the premium version. You’ll get full access to all my past and future articles, all the code examples, extra Python projects, and more.