Well, it turns out that PEP 8 already has this topic covered here:
Note: When using abbreviations in CapWords, capitalize all the letters of the abbreviation. Thus
HTTPServerError
is better thanHttpServerError
.
In other words, the Python convention for names containing acronyms is:
Keep acronyms uppercase in class names (usually, the only part of Python that uses CapWords).
Everywhere else, make them lowercase in order to comply with the other naming conventions.
Below is a demonstration with the ipaddress
module:
>>> import ipaddress # IP is lowercase because this is a module
>>> ipaddress.IPv4Address # IP is uppercase because this is a class
<class 'ipaddress.IPv4Address'>
>>> ipaddress.ip_network # IP is lowercase because this is a function
<function ip_network at 0x0242C468>
>>>