I've seen PyPI distribution names as well python package names with numbers in them. For example flake8 is one example, where you also import with import flake8
.
According to PyPI and PEP standards, is it OK to have a number in a package name? I know you can't start with a number for syntax reasons, but is it OK in the middle or the end from a standards viewpoint?
First, note that PyPI project names and module names are completely independent; there's nothing stopping you from creating a package foo
that installs a module bar
, and these two names follow separate policies as to what is valid.
Module names are restricted by Python's grammar to be valid identifiers. In Python 2, this means that they must consist of an ASCII letter or underscore followed by zero or more ASCII letters, digits, and/or underscores. In Python 3, Unicode is added, and things get more complicated, but I believe that all-ASCII module names still follow the same restrictions.
The names of projects on PyPI (as specified in PEP 508, among others) must consist entirely of ASCII letters, numbers, .
, -
, and/or _
, and they must begin & end with a letter or number. There is also a normalization policy that enforces case-insensitivity and treats runs of .
, -
, and _
as equal, so foo-bar
and FOO.BAR
are considered the same project.
In addition, PEP 8 has a section on package and module names; it says:
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.
When an extension module written in C or C++ has an accompanying Python module that provides a higher level (e.g. more object oriented) interface, the C/C++ module has a leading underscore (e.g.
_socket
).
So, yes, you can have a number in both a project name and a module name, and the project name can even begin with one!
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