What is the correct Python Package Index file structure?

Viewed 53

I've created a Python library that I've uploaded to PyPI. Below is my current file structure, where mylib.py is where I put my library file. When I import to Python I have to type from mylib import mylib for it to work. I want to just type import mylib instead. I assume it's to do where I've put the file?

packageFolder
├── LICENSE
├── README.md
├── mylib
│   ├── __init__.py
│   └── mylib.py
└── setup.py

Thanks in advance.

1 Answers

Move whatever you've defined in mylib.py that you plan to import (functions, variables, etc) into your __init__.py file.

For example, if you currently have to do:

from mylib import mylib
mylib.foo()

Move foo into __init__.py and you can do:

import mylib
mylib.foo()

instead.

Related