Python7 min read

Python Packaging

Create and distribute Python packages.

David Miller
December 18, 2025
0.0k0

Share your Python code.

Project Structure

``` mypackage/ ├── mypackage/ │ ├── __init__.py │ └── module.py ├── tests/ │ └── test_module.py ├── setup.py ├── README.md └── LICENSE ```

Setup.py

```python from setuptools import setup, find_packages

setup( name="mypackage", version="0.1.0", author="Your Name", author_email="email@example.com", description="A short description", long_description=open("README.md").read(), long_description_content_type="text/markdown", url="https://github.com/username/mypackage", packages=find_packages(), classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], python_requires=">=3.8", install_requires=[ "requests>=2.25.0", ], ) ```

__init__.py

```python # mypackage/__init__.py from .module import function1, function2

__version__ = "0.1.0" __all__ = ["function1", "function2"] ```

Build Package

```bash # Install build tools pip install build twine

Build package python -m build

This creates: # dist/mypackage-0.1.0.tar.gz # dist/mypackage-0.1.0-py3-none-any.whl ```

Upload to PyPI

```bash # Test PyPI (recommended first) twine upload --repository testpypi dist/*

Real PyPI twine upload dist/* ```

Install Your Package

```bash # From PyPI pip install mypackage

From local pip install -e .

From GitHub pip install git+https://github.com/username/mypackage.git ```

Remember

- Include README and LICENSE - Version your package properly - Test before uploading to PyPI

#Python#Advanced#Packaging