"Have you ever made a bunch of cool Python functions, but find yourself copying your code over and over again onto new documents? You can solve this problem by creating a Python package. In this tutorial, we’ll walk you through how to create your own Python package!"
]
},
{
"cell_type": "markdown",
"id": "3d3bf097",
"metadata": {},
"source": [
"### Step 1: Creating Your File Structure\n",
"\n",
"The basic file structure for creating a package is as follows:\n",
"\n",
"* Create your setup.py\n",
"\n",
" * This file is used to install your package\n",
"\n",
"* Create a folder with your package name\n",
"\n",
" * Inside the folder, have the following python files:\n",
"\n",
" * __init__.py()\n",
"\n",
" * This file sets up your package\n",
"\n",
" * Python_files_you_want.py\n",
"\n",
" * You can have any number of other .py files\n",
"Setup.py is one of the essential Python files for a package to work. The important things to do here are declare the name of your package and all packages that are used by your package (for example, if you use numpy in one of your .py files, you’ll need to add numpy to your install_requires list."
"***OPTIONAL: there is another way to create the environment with a makefile and an environment.yml, the Github example link does this***"
]
},
{
"cell_type": "markdown",
"id": "42b6e46b",
"metadata": {},
"source": [
"### Step 3: Creating an init.py\n",
"\n",
"\n",
"Next, we’ll need to enter our package folder and create the __init__.py. This file can be blank, but if you want some of your python files to come pre-loaded, import them here with\n",
"\n",
"* From package_name.file_name import function_name\n",
"\n",
" * you can do import * for all functions in the file\n",
"\n",
" * Additionally, you can import files in your document as well if not done in the init file."
]
},
{
"cell_type": "markdown",
"id": "408b017b",
"metadata": {},
"source": [
"##### That’s it! All you need to do now is impoort your package with \n",
Have you ever made a bunch of cool Python functions, but find yourself copying your code over and over again onto new documents? You can solve this problem by creating a Python package. In this tutorial, we’ll walk you through how to create your own Python package!
%% Cell type:markdown id:3d3bf097 tags:
### Step 1: Creating Your File Structure
The basic file structure for creating a package is as follows:
* Create your setup.py
* This file is used to install your package
* Create a folder with your package name
* Inside the folder, have the following python files:
Setup.py is one of the essential Python files for a package to work. The important things to do here are declare the name of your package and all packages that are used by your package (for example, if you use numpy in one of your .py files, you’ll need to add numpy to your install_requires list.
%% Cell type:markdown id:d71d545b tags:
Here's an example of how to create a setup.py:
%% Cell type:code id:bb4e68e3 tags:
``` python
python
fromsetuptoolsimportsetup
setup(
name='JUSTFAIR_Tools',
version='0.1dev',
packages=['JUSTFAIR_Tools'],
license='General Public License 3.0',
install_requires=['matplotlib','pandas','numpy']
#long_description=open('README.md').read(),
)
```
%% Cell type:markdown id:12822d98 tags:
***OPTIONAL: there is another way to create the environment with a makefile and an environment.yml, the Github example link does this***
%% Cell type:markdown id:42b6e46b tags:
### Step 3: Creating an init.py
Next, we’ll need to enter our package folder and create the __init__.py. This file can be blank, but if you want some of your python files to come pre-loaded, import them here with
* From package_name.file_name import function_name
* you can do import * for all functions in the file
* Additionally, you can import files in your document as well if not done in the init file.
%% Cell type:markdown id:408b017b tags:
##### That’s it! All you need to do now is impoort your package with