Portafolio Que hacemos Cobuild Clientes Nosotros Blog Contacto Shop

Basic steps to publish a python package

Foto del autor: Camilo Nova

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:

├── 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
    description='A library to communicate with jenkins',

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.

¿Qué esperas para crecer más?

Los consumidores hoy son digitales, quedarse obsoleto es la receta del fracaso. Comienza ahora tu transformación digital.

Carrera 13 # 98 - 70 OF 204
Bogotá - Colombia