You will need Python 3, a code editor such as IDLE, and a free PyPI account. If pip is unavailable, use the pip troubleshooting guide.
Step 1: Defining the functions
Open IDLE and create a new Python file. Define the functions you want your library to provide. The function below is only an example—you should replace it with the functions you want in your own library.
Example function
def listrange(start, stop, step):
return list(range(start, stop, step))
In this example, listrange creates a list of numbers.
Put any values your own function needs inside the parentheses as
comma-separated arguments.
Step 2: Testing your library locally
Save the file as mylibrary.py in Downloads. Create another script in the same folder and test it:
import mylibrary
numbers = mylibrary.listrange(1, 10, 2)
print(numbers)
The output (if you used the example) should be [1, 3, 5, 7, 9]. If it is different from what you expected for your functions, reopen mylibrary.py and debug it before packaging.
Step 3: Packaging your library
Upload your working .py file below and fill in the
package details. The tool creates a standard Python project ZIP
containing your code, pyproject.toml, README, build
instructions, and a basic import test.
Runs entirely in your browser
Build your package folder
Choose your library file, check the detected details, and download the generated ZIP.
No file selected yet.
Open the downloaded ZIP and move the generated project folder to
Downloads. Your original code will be inside
src/your_library/__init__.py. The pip name may contain
hyphens, while the import name uses underscores.
Step 4: Submitting to PyPI
Register or sign in at PyPI, then verify your email using the link PyPI sends to your inbox. Before uploading, search PyPI to make sure your chosen library name is available.
Name the token after your device, such as “John’s MacBook Air.” For the first release of a new project, create an account-scoped token. After publishing, replace it with a token scoped only to that project.
Copy the complete token beginning with pypi- and
keep it private. If it is ever shared or shown in a screenshot,
revoke it immediately and create another one.
Open Terminal, PowerShell, or Command Prompt, enter the generated
project folder, and run the commands for your system. Replace
your-library-project with the folder name from the ZIP.
macOS or Linux Terminal
cd ~/Downloads/your-library-project
python3 -m venv .venv
source .venv/bin/activate
pip3 install --upgrade build twine
python3 -m build
python3 -m twine check dist/*
python3 -m twine upload --username __token__ dist/*
Windows PowerShell
cd "$HOME\Downloads\your-library-project"
py -m venv .venv
.venv\Scripts\Activate.ps1
py -m pip install --upgrade build twine
py -m build
py -m twine check dist/*
py -m twine upload --username __token__ dist/*
Windows Command Prompt
cd %USERPROFILE%\Downloads\your-library-project
py -m venv .venv
.venv\Scripts\activate.bat
py -m pip install --upgrade build twine
py -m build
py -m twine check dist/*
py -m twine upload --username __token__ dist/*
When Twine asks for the password, paste only the complete API
token beginning with pypi-. The token will remain
invisible while you paste. Do not add __token__
before or after it—the command already supplied that username.
A published PyPI version cannot be replaced. If you need to
upload again, change the version in pyproject.toml,
rebuild, and upload the new files. Or fill in the previous form
again, but increment the version number, then build and upload
the newly generated package.
Install your library on another device
After PyPI confirms the upload, install your package on any compatible computer:
macOS Terminal
pip3 install your-library-name
Windows Command Prompt or PowerShell
pip install your-library-name
Then import it in Python:
import your_library_name
Use pip3 on macOS and pip on Windows.