CyberKeeda In Social Media
Showing posts with label django. Show all posts
Showing posts with label django. Show all posts

How to Upload your Django bundled package to PyPI using twine

Within our last django post, i have demonstrated how we can bundle/package our app into tar.gz format and how we can install it locally.

In case you are not aware, go through the post link.
Within this blog post, we will know cover, how we can upload our django app bundled package into PYPI.
  • Once you have successfully created an account, let's install an additional python package named as twine, open command prompt/terminal and run the below command.
# pip install twine
  • Toggle down to your bundled home directory where you have your bundled tar.gz package under dist folder and run the following command.
# twine check dist/*
Note : PyPI uses your README.rst for to make it's README, descrptions and all other sections under your python package as a part of documentation.
Most of the errors comes while reading your README.rst file from twine as it fails to meet the requirement the formatting required to upload on twine.

In case it gives error, fix the error and try making new bundled package and do run "twine check" to verify if it has been fixed or not.

In order to recreate bundled package, delete old directories (dist and egg-info) and rerun previous command to rebundle it.

# python sdist
One all errors are fixed, we are ready to upload it on PyPi website, use the below command to upload your package.
# twine upload dist/*
It will ask for your credentials, use the same newly created PYPI account credentials to upload it under your username.
Upon successful upload, we can check our PyPi account, package will be uploaded with formatted description mentioned within our README.rst file.

Our django-filesnow screenshot looks like below screenshot.

Read more ...

How to make your Python Django App Reusable

Django is cool and it's features like any other python libraries and frameworks are way more cooler then it.

One of the best feature is to make your django app easily distributable for re usability.

Within this blog post, we will cover.
  • How can we build a django app a python package as xyz.tar.gz
  • How can be uploaded our created django app python package to Python Package Index, simple know as PyPI.
  • How we can Install our created package locally via tar.gz file.
  • How can we install using standard pip command as "pip install your_py_package"
  • We assume you already have a running Django Project and beneath it there must be an application, which you want to package and make it disributable.
  • Here in this blog post we already have a Django project named as docdocGo and within it we have created a django application named as FilesNow, we will cover all things taking it an example.
  • FilesNow is an django application, that can be used to download contents from a AWS S3 bucket within it's temporary directory and serve it as a presentable media to view or download for a user, it deletes the files after a fix set interval. 
  • FilesNow on GitHub link
Here is how our django project and it's  directory look like.


  • Python 3+
  • Django 2.2+
  • PIP
  • Twine ( pip install twin )

Lets proceed and how to Package our filesnow django app.
  1. Create a new empty directory outside our django project and name it something relevant to your app, here we will use it name as django-filesnow.
  2. Copy the entire application directory and paste under newly created directory.
  3. Toggle to directory django-filesnow and lets move ahead and create few required files within it.
  • Create a file django-filesnow/README.rst with the below content and do replace with your own.
Content of django-filesnow/README.rst

FilesNow is a Django app to download documnets, images 
from AWS S3 and serve is a temporary static content to customers.

FilesNow is a way to serve AWS S3 documents/media files
without giving access to your s3 buckets.

FilesNow itself cleans it's downloaded presentable
files, as such maintainig a healthy file system

AWS Boto3 Framework : pip install boto3
Configure AWS Credentilas using command : aws configure

Quick start

1. Add "filesnow" to your INSTALLED_APPS setting like this::


2. Include the polls URLconf in your project like this::

    path('filesnow/', include('filesnow.urls'))

3. Start the development server ``python runserver``

4. Visit and explore it.
  • Create a license file django-filesnow/LICENSE , choose license as per requirement of yours ( GNU, BSD, MIT ) etc, Choose a license website ( ) can help you to guide about your required license and it's content. I have used MIT license and you can find it's content within my Github repo.
  • Create two setup files within same directory and name it as django-filesnow/setup.cfg   and django-filesnow/ with the below content and do replace with your own.
Content of django-filesnow/setup.cfg
name = django-filesnow
version = 0.1
description = A Django app to download cloud contents.
long_description = file: README.rst
url =
author = Jackuna
author_email =
license = MIT License
classifiers =
    Environment :: Web Environment
    Framework :: Django
 Framework :: Django :: 2.2
    Intended Audience :: Developers
    License :: OSI Approved :: MIT 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

include_package_data = true
packages = find:
Content of django-filesnow/
from setuptools import setup

  • Only Python modules and packages are included in the package by default. To include additional files, we’ll need to create a file.  To include the templates, the README.rst and our LICENSE file, create a file django-polls/ with the following contents:
Content of django-filesnow/
include LICENSE
include README.rst
recursive-include filesnow/static *
recursive-include filesnow/templates *
So now we are all done with creation of required files in order to package your app, lets toggle again into the parent directory ( django-filesnow )and open a terminal/command prompt and run the below command to build our package.
# python sdist
Once command ends with successfully, and additional directory with name "dist" will be created, it contains our bundled and packaged django app, in our case  django-filesnow-0.1.tar.gz has been created.

Thus we have packaged our django app by name django-filesnow-0.1.tar.gz, we can distribute it as per your requirement, like uploading to repositories like github, email, uploading to any forum or website.

Let's know how to install our packaged filesnow django app django-filesnow-0.1.tar.gz, use the below command to install it.
# python -m pip install --user django-polls-0.1.tar.gz
Within Above command will install it, for windows we can located the installed application by name "filesnow" under directory.


Please note:
Above highlighted in red may varry, depending upon your system and package.
Package will be installed by name filesnow only not django-filesnow.
Within next post, we will know the remaining topics !

Read more ...
Designed By Jackuna