How to send a package to PyPi?

Viewed 4158

i wrote a little module and i would like to know what are the basic steps to package it in order to send it to pypi:

  • what is the file hierarchy?
  • how should i name files?
  • should i use distutils to create PKG-INFO?
  • where should i include my documentation (made with sphinx)?
5 Answers

Most important thing is prepare your setup.py properly. Then:

  • setup.py sdist bdist_wheel to generate distribution archives to dist/ folder
  • twine upload dist/* to upload the archives to PyPi (with your PyPi username/password)

Here is an example of setup.py:

from setuptools import setup, find_packages

with open('README.md') as readme_file:
    README = readme_file.read()

with open('HISTORY.md') as history_file:
    HISTORY = history_file.read()

setup_args = dict(
    name='elastictools',
    version='0.1.2',
    description='Useful tools to work with Elastic stack in Python',
    long_description_content_type="text/markdown",
    long_description=README + '\n\n' + HISTORY,
    license='MIT',
    packages=find_packages(),
    author='Thuc Nguyen',
    author_email='gthuc.nguyen@gmail.com',
    keywords=['Elastic', 'ElasticSearch', 'Elastic Stack', 'Python 3', 'Elastic 6'],
    url='https://github.com/ncthuc/elastictools',
    download_url='https://pypi.org/project/elastictools/'
)

install_requires = [
    'elasticsearch>=6.0.0,<7.0.0',
    'jinja2'
]

if __name__ == '__main__':
    setup(**setup_args, install_requires=install_requires)

You can find more detail tutorial here: https://medium.com/@thucnc/how-to-publish-your-own-python-package-to-pypi-4318868210f9

Related