{"id":784,"date":"2023-08-03T22:38:36","date_gmt":"2023-08-03T22:38:36","guid":{"rendered":"https:\/\/www.w3computing.com\/articles\/?p=784"},"modified":"2023-08-23T16:20:29","modified_gmt":"2023-08-23T16:20:29","slug":"create-publish-own-python-package-pypi","status":"publish","type":"post","link":"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/","title":{"rendered":"Create and Publish Your Own Python Package on PyPI"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Python packages serve as fundamental building blocks of Python software. They are modular, reusable chunks of code that perform specific tasks and can be easily integrated into larger systems. In the context of collaborative and open-source development, Python packages hold immense importance. They enable developers to encapsulate and distribute code to be used by others, avoiding duplication of effort and promoting code reusability. Additionally, well-maintained Python packages can elevate the software ecosystem by offering reliable, tried-and-tested functionality to fellow developers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Python Package Index, commonly known as PyPI, is a repository of software for the Python programming language. PyPI helps Python developers find and install software developed and shared by the Python community. It serves as a common platform where developers can publish their Python packages and where users can find and install them. As of writing, PyPI hosts a plethora of packages catering to a wide array of tasks, further augmenting Python&#8217;s utility and flexibility. Today, we will learn how you, too, can contribute to this vibrant ecosystem by creating and publishing your very own Python package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this comprehensive guide, we will delve into the step-by-step process of creating and publishing your own Python package to the Python Package Index (PyPI). With practical examples and code snippets, we aim to provide a clear pathway for intermediate and advanced Python developers to share their software with the larger Python community. From writing your first lines of code to making your package available for install via pip, each phase of the journey will be explored in detail.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Pre-requisites<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Required Tools: Python, pip, setuptools, wheel, twine<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To successfully follow this guide, certain tools are required, each serving a specific purpose in the package creation and distribution process. Let&#8217;s outline these key components:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Python<\/strong>: Of course, Python is fundamental. We assume you have Python installed and that you&#8217;re comfortable with its syntax and conventions. This guide is written for Python 3.6 and above.<\/li>\n\n\n\n<li><strong>pip<\/strong>: This is the package installer for Python. We will use pip to install other necessary tools and eventually to install and test your own package from PyPI.<\/li>\n\n\n\n<li><strong>setuptools and wheel<\/strong>: These are Python libraries that we&#8217;ll use to package the source code. setuptools is used for building packages, and wheel is used for creating a .whl binary distribution file, which is a more modern, faster alternative to the .egg format.<\/li>\n\n\n\n<li><strong>twine<\/strong>: This is a utility for publishing Python packages on PyPI. We will use it to securely upload the distribution package to PyPI.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Ensure all these tools are correctly installed and up-to-date on your system. They can be installed or upgraded using pip, Python&#8217;s package installer.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Knowledge Assumptions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This guide assumes that you are comfortable with Python programming and have a good understanding of object-oriented programming (OOP) concepts. You should know how to write functions and classes in Python, and understand concepts like inheritance, encapsulation, and polymorphism.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition, as we&#8217;ll use command line interfaces (CLI) extensively, it&#8217;s essential that you&#8217;re familiar with basic command line operations. While this guide will include all necessary commands, understanding them will make the process smoother and more meaningful.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Last but not least, having a basic understanding of software versioning, Git, and GitHub will be beneficial, as we&#8217;ll briefly touch upon these topics in the context of package maintenance. While not strictly necessary for creating and publishing a package, they are important aspects of the broader software development landscape.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step-by-Step Guide to Creating a Python Package<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Up Your Project Structure<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Common project structure in Python<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">When developing a Python package, it is important to maintain a standard project structure, which helps organize code and make it easier for others to understand and contribute. A common Python project structure often looks like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">my_package\/\n\u2502\n\u251c\u2500\u2500 my_package\/\n\u2502   \u251c\u2500\u2500 __init__.py\n\u2502   \u2514\u2500\u2500 module.py\n\u2502\n\u251c\u2500\u2500 tests\/\n\u2502   \u2514\u2500\u2500 test_module.py\n\u2502\n\u251c\u2500\u2500 .gitignore\n\u251c\u2500\u2500 LICENSE\n\u251c\u2500\u2500 README.md\n\u2514\u2500\u2500 setup.py<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what each component represents:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>my_package\/<\/code> (outer): This is the root directory of your project. It&#8217;s named after your package.<\/li>\n\n\n\n<li><code>my_package\/<\/code> (inner): This is the actual Python package. This directory contains all of your source code (i.e., modules, scripts, sub-packages).<\/li>\n\n\n\n<li><code>__init__.py<\/code>: This file is required for Python to recognize the directory as a package. It can be empty or define any initialization code for the package.<\/li>\n\n\n\n<li><code>module.py<\/code>: This is an example of a module file. Your package will have one or more of these, each containing your code.<\/li>\n\n\n\n<li><code>tests\/<\/code>: This directory includes your package&#8217;s unit tests. While not necessary for a minimal working package, it&#8217;s considered a best practice to include tests.<\/li>\n\n\n\n<li><code>.gitignore<\/code>: This file tells Git which files (or patterns) it should ignore. It&#8217;s generally used to exclude certain files from your Git repository.<\/li>\n\n\n\n<li><code>LICENSE<\/code>: This file (often in the root directory) contains the license under which your project is made available.<\/li>\n\n\n\n<li><code>README.md<\/code>: This file contains information about the project, such as what the package does, how to install and use it, and how to contribute to it.<\/li>\n\n\n\n<li><code>setup.py<\/code>: This is the build script for setuptools. It provides setuptools with package details and instructions on how to build and install the package.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Step-by-step code walkthrough on setting up the structure<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To set up this structure, you will primarily use your operating system&#8217;s file and directory operations. The following are general commands using a Unix-based command line like Bash:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># Navigate to the location where you want to create the package directory<\/span>\n<span class=\"hljs-built_in\">cd<\/span> \/path\/to\/directory\n\n<span class=\"hljs-comment\"># Create the main directory<\/span>\nmkdir my_package\n\n<span class=\"hljs-comment\"># Move into this main directory<\/span>\n<span class=\"hljs-built_in\">cd<\/span> my_package\n\n<span class=\"hljs-comment\"># Create the inner package directory and the tests directory<\/span>\nmkdir my_package tests\n\n<span class=\"hljs-comment\"># Create the initial files<\/span>\ntouch my_package\/__init__.py my_package\/module.py tests\/test_module.py .gitignore LICENSE README.md setup.py<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This will create the necessary files and directories. You can now start filling these with your code, tests, package data, and other information. Note that your package might be more complex, containing more modules and sub-packages, but this provides a good starting point.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Writing Your Python Code<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Code Organization Best Practices<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">While writing code for your Python package, following certain best practices can help maintain code quality and readability:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Modularity<\/strong>: Split your code into multiple modules and functions based on functionality. Each module or function should do one thing and do it well.<\/li>\n\n\n\n<li><strong>Naming Conventions<\/strong>: Follow Python&#8217;s naming conventions. For example, use <code>snake_case<\/code> for functions and variables, <code>PascalCase<\/code> for classes, and <code>ALL_CAPS<\/code> for constants.<\/li>\n\n\n\n<li><strong>Docstrings<\/strong>: Provide clear, concise docstrings for all public classes, methods, and functions. This will help users understand how to use your functions and also generate automatic documentation.<\/li>\n\n\n\n<li><strong>Error Handling<\/strong>: Handle potential errors gracefully. Use exceptions where appropriate, and provide useful error messages.<\/li>\n\n\n\n<li><strong>Coding Standards<\/strong>: Follow PEP 8, the official style guide for Python code. It covers topics like indentation, comments, naming conventions, etc.<\/li>\n\n\n\n<li><strong>Type Hints<\/strong>: Consider using type hints (PEP 484) for your functions and methods. This can help catch certain types of errors and makes your code easier to understand.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">A Simple Library Code Example<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s create a simple package, <code>my_math<\/code>, which contains a single module, <code>arithmetic<\/code>. In the <code>arithmetic<\/code> module, we define two simple functions, <code>add<\/code> and <code>subtract<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>my_math\/my_math\/arithmetic.py<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-string\">\"\"\"\nA module for performing basic arithmetic operations.\n\"\"\"<\/span>\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">add<\/span><span class=\"hljs-params\">(a: float, b: float)<\/span> -&gt; float:<\/span>\n    <span class=\"hljs-string\">\"\"\"\n    Return the sum of two numbers.\n\n    :param a: The first number\n    :param b: The second number\n    :return: The sum of the numbers\n    \"\"\"<\/span>\n    <span class=\"hljs-keyword\">return<\/span> a + b\n\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">subtract<\/span><span class=\"hljs-params\">(a: float, b: float)<\/span> -&gt; float:<\/span>\n    <span class=\"hljs-string\">\"\"\"\n    Return the difference of two numbers.\n\n    :param a: The first number\n    :param b: The second number\n    :return: The difference of the numbers\n    \"\"\"<\/span>\n    <span class=\"hljs-keyword\">return<\/span> a - b<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">We follow the best practices here: the code is organized into functions that do one thing, we follow Python&#8217;s naming conventions, we provide clear docstrings for our functions, and we use type hints to clarify what types of arguments should be passed to our functions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating the README file<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Importance and uses of a good README<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">A README file is one of the most critical parts of your project. It&#8217;s the first file users and developers see when they visit your project, and it provides crucial information about your package. A good README helps people understand what your package does, why it&#8217;s useful, and how they can use or contribute to it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A README file often serves several purposes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Introduction<\/strong>: It introduces your project to the audience, gives a brief overview, and sets the context.<\/li>\n\n\n\n<li><strong>Instructions<\/strong>: It guides users on how to install and use your package.<\/li>\n\n\n\n<li><strong>Contribution<\/strong>: If your project is open source, the README helps guide potential contributors on how they can help.<\/li>\n\n\n\n<li><strong>Documentation<\/strong>: While not a substitute for full documentation, the README is a good place to include a basic usage example or even a quick reference guide.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Key Components of an Effective README<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here are some key components that you should include in your README:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Project Title<\/strong>: Clearly state the name of the project.<\/li>\n\n\n\n<li><strong>Description<\/strong>: A brief description of what the project is about.<\/li>\n\n\n\n<li><strong>Installation Instructions<\/strong>: Detailed steps on how to install the package.<\/li>\n\n\n\n<li><strong>Usage<\/strong>: A quick start guide or example showing how to use the package. Include code snippets where applicable.<\/li>\n\n\n\n<li><strong>Contribution Guidelines<\/strong>: If your project is open source, provide instructions on how others can contribute.<\/li>\n\n\n\n<li><strong>License Information<\/strong>: Briefly state the license under which your project is released.<\/li>\n\n\n\n<li><strong>Contact Information<\/strong>: Provide your contact information or the project&#8217;s maintainers contact information, in case users have additional questions.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Consider your README as the front page of your project. It should be inviting, informative, and helpful, making it easy for users to understand what your project does and how to use it. Markdown (.md) or reStructuredText (.rst) can be used to format your README and make it more readable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Writing the setup.py file<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">setup.py is and its role<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>setup.py<\/code> file is essentially the build script for your Python package. It provides metadata about your package and contains instructions for packaging your Python code, distributing it, and installing it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s called by tools such as <code>pip<\/code> (for installing your package) and <code>twine<\/code> (for uploading your package to PyPI). It&#8217;s one of the key components of your package and serves as the main entry point for these tools to interact with your package.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Details of the various parts of a setup.py file with code example<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here is an example of what a basic <code>setup.py<\/code> file might look like for our <code>my_math<\/code> package:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> setuptools <span class=\"hljs-keyword\">import<\/span> setup, find_packages\n\nsetup(\n    name=<span class=\"hljs-string\">'my_math'<\/span>,  <span class=\"hljs-comment\"># Required<\/span>\n    version=<span class=\"hljs-string\">'0.1.0'<\/span>,  <span class=\"hljs-comment\"># Required<\/span>\n    description=<span class=\"hljs-string\">'A simple package for basic arithmetic operations.'<\/span>,  <span class=\"hljs-comment\"># Optional<\/span>\n    url=<span class=\"hljs-string\">'https:\/\/github.com\/yourusername\/my_math'<\/span>,  <span class=\"hljs-comment\"># Optional<\/span>\n    author=<span class=\"hljs-string\">'Your Name'<\/span>,  <span class=\"hljs-comment\"># Optional<\/span>\n    author_email=<span class=\"hljs-string\">'yourname@example.com'<\/span>,  <span class=\"hljs-comment\"># Optional<\/span>\n    classifiers=&#91;  <span class=\"hljs-comment\"># Optional<\/span>\n        <span class=\"hljs-string\">'Development Status :: 3 - Alpha'<\/span>,\n        <span class=\"hljs-string\">'Intended Audience :: Developers'<\/span>,\n        <span class=\"hljs-string\">'License :: OSI Approved :: MIT License'<\/span>,\n        <span class=\"hljs-string\">'Programming Language :: Python :: 3'<\/span>,\n        <span class=\"hljs-string\">'Programming Language :: Python :: 3.6'<\/span>,\n        <span class=\"hljs-string\">'Programming Language :: Python :: 3.7'<\/span>,\n        <span class=\"hljs-string\">'Programming Language :: Python :: 3.8'<\/span>,\n    ],\n    packages=find_packages(),  <span class=\"hljs-comment\"># Required<\/span>\n    python_requires=<span class=\"hljs-string\">'&gt;=3.6, &lt;4'<\/span>,\n    project_urls={  <span class=\"hljs-comment\"># Optional<\/span>\n        <span class=\"hljs-string\">'Bug Reports'<\/span>: <span class=\"hljs-string\">'https:\/\/github.com\/yourusername\/my_math\/issues'<\/span>,\n        <span class=\"hljs-string\">'Source'<\/span>: <span class=\"hljs-string\">'https:\/\/github.com\/yourusername\/my_math\/'<\/span>,\n    },\n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what each part does:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>name<\/code>: This is the name of your package. This name is used by pip when installing your package.<\/li>\n\n\n\n<li><code>version<\/code>: The current version of your package. This should follow semantic versioning rules.<\/li>\n\n\n\n<li><code>description<\/code>: A brief description of your package.<\/li>\n\n\n\n<li><code>url<\/code>: The URL for the homepage of your package.<\/li>\n\n\n\n<li><code>author<\/code> and <code>author_email<\/code>: The name and email address of the author of the package.<\/li>\n\n\n\n<li><code>classifiers<\/code>: These help users find your project by categorizing it.<\/li>\n\n\n\n<li><code>packages<\/code>: This tells setuptools where to find your package. In this case, <code>find_packages()<\/code> automatically finds all packages and subpackages.<\/li>\n\n\n\n<li><code>python_requires<\/code>: This specifies the Python versions that your package supports.<\/li>\n\n\n\n<li><code>project_urls<\/code>: This provides handy links to associated sites or pages related to your project.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You will have to modify this file to fit the details of your package, but this provides a general template to get you started.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating the <strong>init<\/strong>.py file<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">The <strong>init<\/strong>.py file<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>__init__.py<\/code> file is a special file in Python. When a directory is considered by Python as a package (i.e., it can be imported as a module), it is because it contains an <code>__init__.py<\/code> file. This file is executed when the package or a module inside the package is imported.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>__init__.py<\/code> file can be left empty, or it can contain valid Python code. This code will be executed when the package is imported, allowing you to initialize any variables, import certain modules by default, or perform any other initialization tasks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the context of packaging, the <code>__init__.py<\/code> file often includes code to import the key functions, classes or variables that the package provides, so that they can be easily accessed directly from the package, rather than from the specific module within the package that they are defined in.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Code example of an <strong>init<\/strong>.py file<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example <code>__init__.py<\/code> file for our <code>my_math<\/code> package:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>my_math\/my_math\/__init__.py<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> .arithmetic <span class=\"hljs-keyword\">import<\/span> add, subtract<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this example, we&#8217;re importing the <code>add<\/code> and <code>subtract<\/code> functions from the <code>arithmetic<\/code> module in the same package (the dot before <code>arithmetic<\/code> denotes the same package). This means that users can directly import these functions from <code>my_math<\/code>, like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> my_math <span class=\"hljs-keyword\">import<\/span> add, subtract<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Instead of having to import them from the <code>arithmetic<\/code> module:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> my_math.arithmetic <span class=\"hljs-keyword\">import<\/span> add, subtract<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This is not necessary, and whether you do it or not depends on how you want users to interact with your package. It can make your package easier to use in some cases.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Building your Package Locally<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Understanding the process of building a Python package<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Before you can publish your package to PyPI, you need to build it. Building your package involves taking your Python code and other files (like the README and the <code>setup.py<\/code> file), and compiling them into a format that can be easily installed and used.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Python uses a standard format for distribution, called a &#8220;wheel&#8221; (.whl file). This format is a binary distribution format, which means it can be quickly installed without needing to compile any code, making installation much faster and smoother for users.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step-by-step guide on how to build the package using setuptools and wheel with command line code<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To build your Python package, you&#8217;ll need the <code>setuptools<\/code> and <code>wheel<\/code> packages. If you don&#8217;t already have them, you can install them with pip:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">pip install --upgrade setuptools wheel<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Once you have setuptools and wheel installed, navigate to the directory containing your <code>setup.py<\/code> file (which should be the top-level directory for your package) in the terminal, and run this command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">python setup.py sdist bdist_wheel<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This command tells setuptools to create a source distribution (sdist) and a binary distribution (bdist_wheel) for your package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The source distribution is a tarball (a .tar.gz file) that includes your <code>setup.py<\/code> file and your Python code. It can be installed with pip, but it requires the user to compile the code, which can be slow and may require additional tools.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The binary distribution is a .whl file that includes your compiled Python code. It can also be installed with pip, and it installs much faster than the source distribution because it doesn&#8217;t require any compilation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After running this command, you&#8217;ll see a <code>dist\/<\/code> directory appear in your package directory. This directory contains the source distribution and binary distribution for your package. These are the files you&#8217;ll upload to PyPI to publish your package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the binary distribution is specific to the Python version and platform you built it on. If you want to provide binary distributions for other Python versions or platforms, you&#8217;ll need to build your package on those versions\/platforms. However, the source distribution can be installed on any Python version and platform.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Publishing Your Python Package to PyPI<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Up Your PyPI Account<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before you can upload your package to PyPI (Python Package Index), you need to set up an account. PyPI is the official third-party software repository for Python. It is where users can find and install your package using pip. Here are the steps to set up an account:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to the PyPI registration page at <a href=\"https:\/\/pypi.org\/account\/register\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/pypi.org\/account\/register\/<\/a>.<\/li>\n\n\n\n<li>Fill in your details, including your name, username, password, and email address. Be sure to choose a username and password that you will remember, as you will need them to upload packages.<\/li>\n\n\n\n<li>You will receive an email to confirm your account. Click the link in the email to verify your account.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Remember to keep your login details secure. You will need them to upload your package and to manage any packages you upload. If you lose your password, you can reset it through the PyPI website.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Building the Distribution Package<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Code example and explanation on creating a distribution package<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">As mentioned earlier, before you can upload your package to PyPI, you need to build it. The building process generates distribution packages, which are archived files that contain everything needed to install your package. Python provides two types of distribution packages &#8211; Source Distributions (.tar.gz files) and Built Distributions (.whl files).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use <code>setuptools<\/code> and <code>wheel<\/code> to create these distributions. If they are not already installed, you can install them with pip:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">pip install --upgrade setuptools wheel<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Once you have setuptools and wheel installed, navigate to the directory containing your <code>setup.py<\/code> file (which should be the top-level directory for your package) in the terminal, and run this command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">python setup.py sdist bdist_wheel<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The <code>sdist<\/code> command tells setuptools to build a source distribution. This will be an archive file with a <code>.tar.gz<\/code> extension that includes your package files and the necessary metadata.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>bdist_wheel<\/code> command tells setuptools to build a &#8220;built&#8221; distribution. This will be an archive file with a <code>.whl<\/code> extension, and it&#8217;s a binary distribution of your package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After running the command, you&#8217;ll find the distribution packages in the <code>dist\/<\/code> directory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remember, you&#8217;ll need to rebuild your distributions whenever you make changes to your package that you want to distribute. If you&#8217;re updating your package, you&#8217;ll also need to increment the version number in your <code>setup.py<\/code> file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Uploading the Distribution Package to PyPI<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">How to use twine to upload your package<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After you&#8217;ve built your distribution packages, you can upload them to PyPI using a tool called <code>twine<\/code>. Twine is a utility for publishing Python packages on PyPI. It\u2019s secure because it uses verified HTTPS connections to upload your distribution packages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, you need to install <code>twine<\/code> if you haven&#8217;t already. You can install it using pip:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">pip install twine<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\">Code example of uploading the distribution package<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Once <code>twine<\/code> is installed, you can use it to upload your distribution packages. Make sure you&#8217;re in the directory that contains your <code>dist\/<\/code> folder (this should be the same directory that contains your <code>setup.py<\/code> file), then run this command:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">twine upload dist\/*<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This command tells <code>twine<\/code> to upload all of the distribution packages in the <code>dist\/<\/code> directory to PyPI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll be prompted to enter your PyPI username and password. Once you enter your credentials, <code>twine<\/code> will upload your packages. If everything goes well, your package will be available on PyPI and can be installed by anyone using pip!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please remember, if you&#8217;re updating your package on PyPI, make sure to increment the version number in your <code>setup.py<\/code> file. PyPI does not allow you to upload the same version of a package twice.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing and Testing Your Published Package<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">How to install your package from PyPI<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After your package is uploaded to PyPI, it can be installed by anyone using pip. You can test this yourself by installing your package from PyPI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To do this, you first might want to create a new virtual environment, to ensure that you&#8217;re testing the installation process in a clean environment. Once you have your new environment ready, you can install your package with this command (replace <code>my_math<\/code> with the name of your package):<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">pip install my_math<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This command tells pip to download and install the <code>my_math<\/code> package from PyPI.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Testing the package to ensure it was uploaded correctly<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After installing your package, you should test it to make sure it was uploaded correctly and works as expected. This can be as simple as importing it and running some basic functionality, or as complex as running a suite of automated tests.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At the very least, you should open a Python interpreter and try to import your package and call some of its functions to make sure they work. For example, if we&#8217;re testing the <code>my_math<\/code> package, we could do:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> my_math\n\nprint(my_math.add(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">2<\/span>))  <span class=\"hljs-comment\"># Should print 3<\/span>\nprint(my_math.subtract(<span class=\"hljs-number\">5<\/span>, <span class=\"hljs-number\">2<\/span>))  <span class=\"hljs-comment\"># Should print 3<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This will confirm whether the package was installed correctly and is working as expected.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remember, the more comprehensive your tests, the more confident you can be that your package works correctly. Ideally, you would have a suite of automated tests that you can run to thoroughly test your package.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Maintaining Your Python Package<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">The importance of version control in package maintenance<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Version control systems are an indispensable tool in modern software development practices and should be utilized for maintaining Python packages. They allow you to keep track of changes made to the code, help in managing updates, bug fixes, and new features, and facilitate collaboration when working in a team.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The most widely used version control system is Git, and platforms like GitHub, Bitbucket, or GitLab provide cloud-based hosting services for Git repositories. These platforms provide additional features like issue tracking, pull requests, and actions for automating workflows like testing and deployment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For Python package maintenance, using a version control system like Git allows you to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep a historical record of changes, which can be useful for tracking down when a bug was introduced or understanding the rationale for a particular piece of code.<\/li>\n\n\n\n<li>Manage different versions of your package. You can use Git tags to mark specific commits as package releases.<\/li>\n\n\n\n<li>Facilitate contributions from others. If your package is open-source, other developers can fork your Git repository, make improvements, and submit these back to you as pull requests.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Updating Your Package<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Updating your package is an integral part of package maintenance. When updating your package, consider the following steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Ensure that your package is correctly versioned. Follow the principles of Semantic Versioning (SemVer). If you&#8217;re fixing a bug, increment the patch number (e.g., 1.0.1 to 1.0.2). If you&#8217;re adding a new feature without breaking backward compatibility, increment the minor number (e.g., 1.0.2 to 1.1.0). If you&#8217;re making changes that break backward compatibility, increment the major number (e.g., 1.1.0 to 2.0.0).<\/li>\n\n\n\n<li>Make sure to update your documentation to reflect any changes or new features.<\/li>\n\n\n\n<li>Consider running unit tests to ensure that your updates didn&#8217;t break any existing functionality. Continuous integration (CI) tools can automate this process every time you push an update to your repository.<\/li>\n\n\n\n<li>Build your package and upload the distribution to PyPI.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Handling User Issues and Feedback<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When your package is being used by others, there will inevitably be feedback, bug reports, and feature requests. Here&#8217;s how to handle them:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Encourage users to submit issues via the issue tracker of your version control platform (like GitHub issues). This keeps everything documented and organized.<\/li>\n\n\n\n<li>Be responsive to issues. Even if you can&#8217;t solve a problem immediately, a quick acknowledgement lets the submitter know that you&#8217;re aware of the issue.<\/li>\n\n\n\n<li>Use labels to categorize and prioritize issues.<\/li>\n\n\n\n<li>Be open to contributions. If someone proposes a bug fix or enhancement, consider their pull request and incorporate it if it aligns with your vision for the package.<\/li>\n\n\n\n<li>Always remember to thank users for their feedback and contributions. This fosters a positive community around your project.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Ensuring Backward Compatibility<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Backward compatibility means that newer versions of your package can replace older versions without disrupting environments where your package is already used. It&#8217;s a crucial aspect of package maintenance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Breaking backward compatibility can frustrate users and lead to unexpected bugs in their projects. Here are some tips for maintaining backward compatibility:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Avoid changing the behavior of existing functions. If you need to change a function, consider creating a new function instead.<\/li>\n\n\n\n<li>If you must change a function, use deprecation warnings to inform users about the upcoming change. This gives them time to update their code.<\/li>\n\n\n\n<li>Use semantic versioning. Increment the major version number whenever you make incompatible changes. This signals to users that they might need to check their usage of your package when they upgrade.<\/li>\n\n\n\n<li>Consider the impact on users before making breaking changes. Sometimes it&#8217;s necessary, but it should not be taken lightly.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Publishing your own Python package is beneficial in several ways. It encourages code reuse, saves time in future projects, and allows others in the community to benefit from your work. It provides a means to showcase your programming skills and can contribute to the open-source community. Additionally, feedback and contributions from other users can improve your code and programming skills.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python packages serve as fundamental building blocks of Python software. They are modular, reusable chunks of code that perform specific tasks and can be easily integrated into larger systems. In the context of collaborative and open-source development, Python packages hold immense importance. They enable developers to encapsulate and distribute code to be used by others, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,6],"tags":[],"class_list":["post-784","post","type-post","status-publish","format-standard","category-programming-languages","category-python","entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Create and Publish Your Own Python Package on PyPI<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create and Publish Your Own Python Package on PyPI\" \/>\n<meta property=\"og:description\" content=\"Python packages serve as fundamental building blocks of Python software. They are modular, reusable chunks of code that perform specific tasks and can be easily integrated into larger systems. In the context of collaborative and open-source development, Python packages hold immense importance. They enable developers to encapsulate and distribute code to be used by others, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-03T22:38:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-23T16:20:29+00:00\" \/>\n<meta name=\"author\" content=\"w3compadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"w3compadmin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/create-publish-own-python-package-pypi\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/create-publish-own-python-package-pypi\\\/\"},\"author\":{\"name\":\"w3compadmin\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\"},\"headline\":\"Create and Publish Your Own Python Package on PyPI\",\"datePublished\":\"2023-08-03T22:38:36+00:00\",\"dateModified\":\"2023-08-23T16:20:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/create-publish-own-python-package-pypi\\\/\"},\"wordCount\":3781,\"commentCount\":0,\"articleSection\":[\"Programming Languages\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/create-publish-own-python-package-pypi\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/create-publish-own-python-package-pypi\\\/\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/create-publish-own-python-package-pypi\\\/\",\"name\":\"Create and Publish Your Own Python Package on PyPI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#website\"},\"datePublished\":\"2023-08-03T22:38:36+00:00\",\"dateModified\":\"2023-08-23T16:20:29+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/create-publish-own-python-package-pypi\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/create-publish-own-python-package-pypi\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/create-publish-own-python-package-pypi\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Articles Home\",\"item\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programming Languages\",\"item\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/programming-languages\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python\",\"item\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/programming-languages\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Create and Publish Your Own Python Package on PyPI\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#website\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/\",\"name\":\"Developer Articles Hub\",\"description\":\"\",\"alternateName\":\"Developer Articles\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\",\"name\":\"w3compadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266\",\"contentUrl\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266\",\"caption\":\"w3compadmin\"},\"sameAs\":[\"http:\\\/\\\/w3computing.com\\\/articles\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create and Publish Your Own Python Package on PyPI","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/","og_locale":"en_US","og_type":"article","og_title":"Create and Publish Your Own Python Package on PyPI","og_description":"Python packages serve as fundamental building blocks of Python software. They are modular, reusable chunks of code that perform specific tasks and can be easily integrated into larger systems. In the context of collaborative and open-source development, Python packages hold immense importance. They enable developers to encapsulate and distribute code to be used by others, [&hellip;]","og_url":"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/","article_published_time":"2023-08-03T22:38:36+00:00","article_modified_time":"2023-08-23T16:20:29+00:00","author":"w3compadmin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"w3compadmin","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/#article","isPartOf":{"@id":"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/"},"author":{"name":"w3compadmin","@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561"},"headline":"Create and Publish Your Own Python Package on PyPI","datePublished":"2023-08-03T22:38:36+00:00","dateModified":"2023-08-23T16:20:29+00:00","mainEntityOfPage":{"@id":"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/"},"wordCount":3781,"commentCount":0,"articleSection":["Programming Languages","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/","url":"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/","name":"Create and Publish Your Own Python Package on PyPI","isPartOf":{"@id":"https:\/\/www.w3computing.com\/articles\/#website"},"datePublished":"2023-08-03T22:38:36+00:00","dateModified":"2023-08-23T16:20:29+00:00","author":{"@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561"},"breadcrumb":{"@id":"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.w3computing.com\/articles\/create-publish-own-python-package-pypi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Articles Home","item":"https:\/\/www.w3computing.com\/articles\/"},{"@type":"ListItem","position":2,"name":"Programming Languages","item":"https:\/\/www.w3computing.com\/articles\/programming-languages\/"},{"@type":"ListItem","position":3,"name":"Python","item":"https:\/\/www.w3computing.com\/articles\/programming-languages\/python\/"},{"@type":"ListItem","position":4,"name":"Create and Publish Your Own Python Package on PyPI"}]},{"@type":"WebSite","@id":"https:\/\/www.w3computing.com\/articles\/#website","url":"https:\/\/www.w3computing.com\/articles\/","name":"Developer Articles Hub","description":"","alternateName":"Developer Articles","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.w3computing.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561","name":"w3compadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266","url":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266","contentUrl":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266","caption":"w3compadmin"},"sameAs":["http:\/\/w3computing.com\/articles"]}]}},"featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"w3compadmin","author_link":"https:\/\/www.w3computing.com\/articles\/author\/w3compadmin\/"},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/784","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/comments?post=784"}],"version-history":[{"count":9,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/784\/revisions"}],"predecessor-version":[{"id":793,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/784\/revisions\/793"}],"wp:attachment":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/media?parent=784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/categories?post=784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/tags?post=784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}