Basic steps to publish a python package
Camilo Nova
CEO
I was interested in publishing some utility code we use on a daily basis, we were always download the file and added into the projects, making us hard to keep it updated as the amount of projects grow. In order to have a simple package we can use I will show you how to publish on Pypi.
First you have to create a repository with your code, make sure its public so people can access it later to report issues, project structure should look like this:
├── LICENSE
├── README.md
├── jenkinsconnector
│ ├── __init__.py
└── setup.py
This is a simple layout were you need to change only two files.
jenkinsconnector it is a folder with the name of the project, make sure it is all lowercase and only separated by _ if you need to, inside you can put all the code you need, for making a simpler layout I've used __init__.py file to put the code, it looks like this jenkins-connector.
Later you have to set contents inside
setup.py file, so it looks like this:
from setuptools import setup
setup(
name='jenkinsconnector',
version='0.1',
description='A library to communicate with jenkins',
url='https://github.com/AxiaCore/jenkins-connector',
author='AxiaCore',
author_email='info@axiacore.com',
license='MIT',
packages=['jenkinsconnector'],
zip_safe=False,
)
You can change all the information, but make sure that
packages has the name of the folder you are adding, so it can collect it to the package, and also keep zip_safe=False unless you know what you are doing.
To finish you need to publish this package to the Pypi index, like this:
$ python setup.py register sdist upload
The command output will ask you for user and password, you can register easily, and thats it, your package should be available to install using the package name, like this:
$ pip install jenkinsconnector
There's more, but for sure this steps are going to make your starting easy.
Written by Camilo Nova
As the Axiacore CEO, Camilo writes about the intersection of technology, design, and business. With a strategic mindset and a deep understanding of the industry, he is dedicated to helping companies grow.