Insights

Basic steps to publish a python package

Photo of the author: Camilo Nova

Camilo Nova

  •  

1 min read.


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.

Subscribe to our monthly newsletter

Learn more

Primeros días en AxiaCore

Hace más o menos un mes, mientras aún trabajaba en mi antigua compañía, decidí asistir a una de las conferencias sobre Django...

Author Pablo Vallejo Pablo Vallejo

Pointer events en CSS

Sin importar el orden de apilamiento o posición es posible controlar por medio de css con una simple propiedad el evento del...

Photo of the author: Jorge Olaya Jorge Olaya

Clima Organizacional

En un mundo altamente competitivo, y un entorno en constante dinamismo, es necesario implementar estrategias para optimizar r...

Photo of the author: Carolina Muñoz Carolina Muñoz

Own your tech to own your destiny