# Creating a Python Package So, you wrote some code and want to make it a package that is installable by Pip; how do you do it? ## Get your files ready To upload your work to PyPi (Python Package Index) and have another download it using Pip, you will need your code files in one directory and **5 supporting** files. **1. The setup.cfg file** This file includes information about the project, its author, and its repository. In addition to other kinds of information such as dependencies and licenses used for the project. Here's an example of a setup.cfg file looks like. > [metadata] name = NAME_OF_YOUR_PROJECT version = 0.0.1 author = YOUR_NAME author_email = YOUR_EMAIL description = WHAT IS THE REASON YOU BUILD THIS PROJECT AND WHAT IT DOES long_description = file: README.md long_description_content_type = text/markdown url = GITHUB REPOSITORY LINK classifiers = Programming Language :: Python :: 3 License :: OSI Approved :: Apache Software License Operating System :: OS Independent > [options] packages = find: python_requires = >=3.7 include_package_data = True The [options] sections deal with dependencies. The line `Package = find:` works automatically to detect your package dependencies. **2. pyproject.toml** This file includes the tools Python needs to create a PyPi package. However, it often just contains a few lines of code. This template will work for most cases. > [build-system] > requires = [ > "setuptools>=42", > "wheel" > ] > build-backend = "setuptools.build_meta" **3. License file** There are many different open-source licenses; choosing depends on your goal and the nature of your project. If you need help deciding on a license to read about the other options available [this](https://choosealicense.com/) website, you can help you out. Once you choose your license, you will need to add it to the **setup.cfg** file in a PyPi accepted format. You can find all supported license formates [here](https://pypi.org/classifiers/). **4. README file** This often a markdown file with a detailed explanation of your package and what it does. **5. A Python __ init __ file** The last file you need to create before you start uploading your package is an __ init __ .py file. This file tells PyPi that this folder is a package. This file can be empty. ## After all the files are done Once all your files are ready, we can move on to the next step. To upload a package to [PyPi](https://pypi.org/), you need to register an account thereby set a username and a password (if you want to test your packages before making them public, upload them to [testPyPi](https://test.pypi.org/) first). ## Build your package locally Now, run the command line from the directory of your package. 1. To build the package ``` py -m pip install --upgrade build ``` then ``` py -m build ``` 2. Install Twine Twine is a tool to help you create the package. ``` pip install twine ``` 3. Upload your package to testPyPi/ PyPi If you're uploading a new package, run ``` py -m twine upload --repository PyPI dist/* ``` And input your username and password. But if you want to upload a new version to an existing package, run. ``` py -m twine upload --skip-existing dist/* ``` And input your username and password. Voila, your package is published!!