Sunday, April 28, 2024
HomePythonPackaging and distributing your python libraries

Packaging and distributing your python libraries


Hello there fellow coders. This publish will go over the fundamentals of packaging and deploying your python libraries. So with out losing a minute lets get began..

Folder construction

So very first thing first. What must be your folder construction? At minimal you may have solely two information. The primary one must be the setup.py file and the second must be your module file. However at this time I’m not going to speak concerning the very fundamentals. At present we’re going to comply with this folder construction:

My_module/
    LICENSE.txt
    README.txt
    setup.py
    My_module/
        <a href="http://freepythontips.wordpress.com/2013/07/28/what-is-__init__-py/">__init__.py</a>

Right here I’ve 4 information. The License file incorporates the license below which you need to distribute your module. So lets transfer on. What must be our second step? Clearly it must be to explain our module and write some meta information into the setup.py file.

Describing your module

The setup.py file is the guts of any python module or library. It describes the module and lists another helpful data concerning the module prefer it lists any dependencies on which a module relies upon and it additionally tells distutils the place to seek out the mandatory scripts of this module. So lets describe our module with the assistance of our setup.py file.

from distutils.core import setup

setup(
    title="My tremendous module",
    model='0.1dev',
    packages=['My_module',],
    license="Inventive Commons Attribution-Noncommercial-Share Alike license",
    long_description=open('README.txt').learn(),
)

Right here we might have rewritten the long_description ourselves however we reused our README file. We wrote ‘dev’ within the model as a result of we nonetheless shouldn’t have something in our module however we’re shifting towards the 0.1 launch. When you’ve gotten sufficient code in your module then be at liberty to drop ‘dev’ from the model subject. Now the following step is to make our first launch.

Making your first launch

So how will we make our first launch? Simply comply with me. Your launch ought to have a single archive file. It may be simply made with this command.

$ python setup.py sdist

Simply go to the basis of your module folder and execute this command. It’ll create a subdirectory with the title of dist and can bundle your entire module scripts and different information right into a single archive file able to be uploaded on PyPI (Python Bundle Index). This archive file can have the default extension of zip on home windows and tar.gz on POSIX techniques.

Publishing your module

Now that archive file may be uploaded anyplace for distribution however we are going to give attention to PyPI. To be able to add on PyPI you’ll first should make an account on http://pypi.python.org/pypi. After that you’ll have to register your bundle on PyPI like this:

$ cd path/to/My_module
$ python setup.py register

Simply use your current login. Afte that run the next command to add it to PyPI.

$ python setup.py sdist add

This may make the distribution one time extra and can add it to PyPI. Now you need to be happy with your self as a result of you’ve gotten simply contributed to the opensource world. I hope you favored my publish. If you wish to examine setup.py then go right here. For additional research i like to recommend the Hichhikers information to packaging. I hope you favored at this time’s publish. Do share your views within the feedback beneath and keep tuned for the following publish.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments