What is the naming convention in python community to set names for project folders and subfolders?
my-great-python-project my_great_python_project myGreatPythonProject MyGreatPythonProject
I find mixed up in the github. Appreciate your expert opinion.
modules (filenames) should have short, all-lowercase names, and they can contain underscores; packages (directories) should have short, all-lowercase names, preferably without underscores; classes should use the CapWords convention.
A package is basically a directory with Python files and a file with the name __init__ . py. This means that every directory inside of the Python path, which contains a file named __init__ . py, will be treated as a package by Python.
There are three conventions, which you might find confusing.
PEP8 defines a standard for how to name packages and modules:
Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.
Even though it's in PEP8, many packages use underscores and the community doesn't consider it poor practice. So you see many names like sqlalchemy_searchable
, etc.
Although you can create a folder with a name which does not match your package name, it's generally a bad idea to do so because it makes things more confusing.
So you'll usually use all-lowercase names with underscores for your folders.
The name of a package when it's installed doesn't need to match the name it's published to on pypi (the source for pip
installs). Packages on pypi
tend to be named with hyphens, not underscores. e.g. flask-cors, which installs the package flask_cors
.
However, you'll note that if you follow-up on this example that flask-cors's GitHub repo defines the package code in a flask_cors/
directory. This is the norm.
It gets a bit messy though, because pip
package installation is case-insensitive and treats underscores and hyphens equivalently. So Flask-Cors
, fLASK_cOrs
, etc are all "equivalent". Personally, I don't like playing games with this -- I recommend just naming packages on pypi in all-lowercase with hyphens, which is what most people do.
Disclaimer: I don't own or maintain sqlalchemy-searchable
or flask-cors
, but at time of writing they're good examples of packages with underscores in their names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With