DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • DZone's Article Submission Guidelines
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Extending Java APIs: Add Missing Features Without the Hassle
  • Auditing Tools for Kubernetes

Trending

  • DZone's Article Submission Guidelines
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Extending Java APIs: Add Missing Features Without the Hassle
  • Auditing Tools for Kubernetes
  1. DZone
  2. Coding
  3. Languages
  4. Best Practices of Publishing a Python Module

Best Practices of Publishing a Python Module

If you're seeking to make a contribution to the Python package in the form of a module, make sure you have everything you need.

Soumyajit Basu user avatar by
Soumyajit Basu
CORE ·
Oct. 22, 18 · Tutorial
Like (11)
Save
Tweet
Share
6.92K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I will go through the best practices that a Python aspirant should adhere to when making a contribution to the Python package index.

Requirements

To begin with, if you want to publish a module in the Python community there is some standardization that you would need to follow:

  1. Your project should be packaged inside one single directory.
  2. There should be a setup.py in your project structure. setup.py allows you to specify the project configuration and to run packaging commands.

It is very important to know that there are following parameters that should be taken care of when setting up your module configuration

  • The classifiers array that contains information like the "Intended Audience," "Programming Language," and "License" of your module.
  • The  install_requires  array that contains all the modules required.
  • The packages  array contains all the packages that are present within the module.
  • The download_url  which can be used to download the package.
  •  console_scripts if any, to run any particular script on the console for your module.
  •  name of your module.
  •  author of your module.
  •  version of your module.

P.S: Make sure the long description has been configured as well so that you have the module description in PyPi as well. For that, you need to have a README file in your repository. Follow the code block to upload the README to PyPi.

with open('README.md') as f:
    long_description = f.read()


Now, after that pass these two parameters inside the tuple  setup() .

long_description = long_description,
long_description_content_type = 'text/markdown'


You should be well versed with version control system and creating release tags once you think you are prepared to deploy your module.

Creating Release Tags

1. To create a release tag you should be having the latest code in your release branch. Run the following code to create a release tag run the following code.

git tag <release_version>

2. Once your release tag has been created run the following code to push the release tag on GitHub or any other source repository using this code block.

git push origin <release_version>

3. Be sure to document your release notes to give the user a clear view of what has been deployed in the latest module version.

Packaging Steps

1. First, create a source distribution. The kind of distribution also known as "Package" requires a build step when installed by pip.

python setup.py sdist


But we would want to install a wheel (a built package) which is faster to install than a source distribution.

python setup.py bdist_wheel


Uploading a Package to PyPi

To upload a module to PyPi follow these steps:

First of all, you need to have a module installed called twine. This helps you upload your binary distribution on PyPi with the latest release tag.

To upload your module to PyPi as a Beta version using twine please follow this code snippet:

# Release version to TestPyPi
twine upload --repository-url https://test.pypi.org/legacy/ dist/*\r


To upload your module as a major release version to PyPi please follow this code snippet

# Release version to PyPi
twine upload dist/*\r
Python (language) Release (agency)

Opinions expressed by DZone contributors are their own.

Trending

  • DZone's Article Submission Guidelines
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • Extending Java APIs: Add Missing Features Without the Hassle
  • Auditing Tools for Kubernetes

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: