Bundling code for others to install
Writing code is one thing; getting it onto other people's machines in a working state is another. Packages solve that distribution problem. Each one wraps a set of files together with metadata: a name, a version number, a description, and a list of other packages it needs. That bundle is uploaded to a registry, a public catalogue such as npm for JavaScript, PyPI for Python, or Packagist for PHP. A package manager then fetches it on request and puts it where your project can find it.
The closest everyday comparison is an app store for code. You search for what you need, install it with one command, and update it later when a newer version comes out.
Installing from a registry
Each ecosystem has its own tool, but the idea is the same:
npm install dayjs # JavaScript, from npm
pip install requests # Python, from PyPI
composer require guzzlehttp/guzzle # PHP, from Packagist
After installing, you import the code as usual. In Node.js, import dayjs from "dayjs" makes the package available in your file.
Package vs module
A module is a single file of code you can import. A package is the publishable unit that may contain many modules, along with the metadata that tells a package manager how to install it. The requests package for Python, for instance, is made of several module files working together.
One wrinkle: Python also uses "package" for any folder of modules on your disk, even one never published anywhere. When people talk about installing packages, though, they mean the distributable kind.
Once your project installs a package, that package is a dependency of your project. Many packages exist to deliver a library, while others provide command-line tools.
Learn more
Last updated