How to publish a Django package to PyPi?

PyPI · The Python Package Index

pip

pip install django-package-by-me

How do you do this?

PyPi

  1. How can I make a django package
  2. How to upload it to PyPi

Making a django package

  1. Create a parent directory named django-polls and create another directory named polls
  2. Copy the django app directories you want to package into the polls directory.
  3. Create a file django-polls/README.rstand add following content django-polls/README.rst with the following contents (This is for documentation purpose):
=====
Heading
=====
Description hereDetailed documentation is in the "docs" directory.Quick start
-----------
1. Add "polls" to your INSTALLED_APPS setting like this::INSTALLED_APPS = [
...
'polls',
]
2. Include the polls URLconf in your project urls.py like this::url(r'^polls/', include('polls.urls')),3. Run `python manage.py migrate` to create the polls models.4. Start the development server and visit http://127.0.0.1:8000/admin/
to create a poll (you'll need the Admin app enabled).https://www.youtube.com/watch?v=YIdXBq2_RN8
5. Visit http://127.0.0.1:8000/polls/ to participate in the poll.

4 . Also create a LICENSE file in the same directory

5. Create a setup.cfgfile

[metadata]
name = django-polls
version = 0.1
description = A Django app to conduct Web-based polls.
long_description = file: README.rst
url = https://www.example.com/
author = Your Name
author_email = yourname@example.com
license = BSD-3-Clause # Example license
classifiers =
Environment :: Web Environment
Framework :: Django
Framework :: Django :: X.Y # Replace "X.Y" as appropriate
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Topic :: Internet :: WWW/HTTP
Topic :: Internet :: WWW/HTTP :: Dynamic Content

[options]
include_package_data = true
packages = find:

6. Create a setup.pyfile

from setuptools import setup

setup()

7. Create MANIFEST.in

include LICENSE
include README.rst
recursive-include polls/static *
recursive-include polls/templates *
recursive-include docs *

The directory structure will be like

django-polls
— README.rst [file]
— LICENSE [file]
— setup.cfg [file]
— setup.py [file]
— MANIFEST.in [file]

— polls [dir]
— — [app directories]
— — ..
— — ..

8. python setup.py sdistto build the package
Now you may see some changes in the directory

9. Install twine pip install twine

10. Create an account on PyPi

11. twine upload dist/*

Enter PyPi username and password

Now you’re done with uploading the package. You can now install the package using pip install

Documentations

  1. Packaging Python Projects
  2. Video Guide

--

--

Entrepreneur | Storyteller | ejasmuhammed.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store