Packaging and Distributing
python Modules
Micropyramid
PyPi
PyPI - the Python Package Index
PIP Usage
installing and managing Python packages.
sudo apt-get install python-pip
Pip install [package-name]
Pip uninstall [package-name]
Pip list # or freeze
Pip search [text]
pip show [package-name]
Uses of packaging
Re-usability
Publishing
Rules for creating package_name
All lowercase
Unique name on pypi
Folder Structure
Packagename
Packagename
__init__.py
Package_file
Setup.py
Mkdir periodic_table
Create periodic_table/periodic_table/__init__.py
Create periodic_table/periodic_table/ptable.py
└── periodic_table/
├── periodic_table/
│ ├── __init__.py
│ ├── ptable.py
└── setup.py
Let’s Start
ptable.py
ptable_data = {
"H": "Hydrogen",
"O": "Oxygen",
"Zn": "Zink"
}
def get_name(symb):
return ptable_data.get(symb, None)
def get_symb(name):
for item in ptable_data:
if ptable_data[item] == name:
return item
return None
periodic_table/setup.py
from setuptools import setup
setup(name='ravi_periodic_table',
version='0.1',
description='chemistry symbols and name',
url='http://github.com/ravigadila/ravi_periodic_table',
author='ravigadila',
author_email='ravi@micropyramid.com',
license='MIT',
packages=['periodic_table'],
zip_safe=False)
pip install .
pip install -e . # installing with symlink
To install package Locally
Distributing on Pypi
Register New account: https://pypi.python.org/pypi
https://pypi.python.org/pypi/twine
pip install twine
.pypirc
[distutils]
index-servers =
pypi
pypitest
[pypi]
repository=https://pypi.python.org/pypi
username=Martin.Thoma
password=[your password]
[pypitest]
repository=https://testpypi.python.org/pypi
username=Martin.Thoma
password=[your password]
Upload to Pypi
python setup.py sdist bdist_wheel
twine register dist/ravi_periodic_table-0.1.tar.gz
twine register dist/mypkg-0.1-py2.py3-none-any.whl
twine upload dist/*
Setup.py
classifiers=['Topic :: Software Development :: Build Tools',
'Programming Language :: Python :: 3.5',
]
install_requires=[‘django’],
Reach Us
Githu: https://github.com/MicroPyramid/
Blog: https://micropyramid.com/blog/
Meetup: https://www.meetup.com/hyderabad-python-and-django-
meetup-group/
Packaging and distributing python code to Pypi

Packaging and distributing python code to Pypi