Sample project structure for a python package, contains all the necessary files to publish a PyPI package.
pip3 install virtualenvwrapper echo " # python virtualenv source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bash_profile
I'm assuming my PyPI package name is
structure. Also, don't use non-alphabetic characters; for exampl PyPI will fuck up '-' and '_'.
- create a project on Github, add
README, .gitignore, LICENSE. Clone your git repo locally.
- update your
.gitignore(see example) and remove
README.mdcuz PyPI can't even
- create a
- make a folder with your package name to contain your source code.
mkdir structurein my case.
- since the folder will be a module, add
structure/__init__.py; this file will also contain the version, and the packaged methods.
- add any of your Python source code under
structure.pyand import the needed module methods in
- finally, at the root, do
pip3 freeze > requirements.txtto generate list of dependencies you used, so it can install with
pip3 install -r requirements.txt
Now that you have the project, it's time to publish. Navigate to the project root. First, register your package name; this may prompt you to create an account and login if it's your first time:
python setup.py register
Then, if the package name is registered successfully, upload your source to PyPI:
python setup.py sdist upload
Then wait for a bazillion years for PyPI to update it on their server before you can
pip install it.
./index.py is a test file ignored in
setup.py. A close thing to npm's
node_modules is to create a virtual env to install dependencies and run code from:
# go to the root of your project folder to create env virtualenv env # activate the created virtual env source env/bin/activate # type 'deactivate' inside to quit # install the package inside env pip3 install -U structure # Get ready the source code below before run: python3 index.py
./index.py there's a sample code:
# the package import structure # using class g1 = structure.greeter() g1.greet() # using module method structure.hi()