# Modules and Packages

Stop writing everything in one file. You'll import modules from Python's standard library, split your own code into modules and a package, and use the line that lets a file be both a program and a module. Then you'll make a virtual environment, install packages with pip and record them in requirements.txt, and build a toolkit for game night.

Updated: November 19, 2026

## [Modules in Python](https://www.ask-codey.com/courses/python-in-depth/topics/python-modules)

1. [import and the Standard Library](https://www.ask-codey.com/lessons/python-modules-import-and-standard-library) (Apprentice): Python comes with a standard library of ready-made modules for dice rolls, dates, averages and more, and an import line brings one into your program, whole, by its names, or under a shorter name.
2. [Your Own Modules and Packages](https://www.ask-codey.com/lessons/python-modules-your-own) (Apprentice): Any .py file is a module another file can import, so a growing program is split into files by job, a folder of them with \_\_init\_\_.py becomes a package, and the \_\_name\_\_ check keeps a file's own test lines from running when it's imported.

## [Packages and Virtual Environments](https://www.ask-codey.com/courses/python-in-depth/topics/python-packages-and-environments)

1. [Virtual Environments and pip](https://www.ask-codey.com/lessons/python-venv-and-pip) (Apprentice): A virtual environment gives each Python project its own private set of packages, pip installs packages into it from PyPI, and a requirements.txt with exact versions lets any computer install the same set with one command.

## [Exercise: Game Night Toolkit](https://www.ask-codey.com/courses/python-in-depth/topics/exercise-python-game-night-toolkit)

1. [Exercise: Game Night Toolkit](https://www.ask-codey.com/lessons/exercise-python-game-night-toolkit) (Apprentice): Finish a game night package of modules, dice and scores, keep a try-out line from running on import, connect the modules with import lines, and run it all from its own virtual environment with pinned requirements.

Source: https://www.ask-codey.com/courses/python-in-depth/chapters/python-modules-and-packages
