- PEP8.
- Django Coding Style.
- Use single-quotes for strings.
For consistency, prefer the following libraries to others that perform the same tasks:
- Fabric for project tasks
- Flask for light web apps or Django for heavy web apps
- boto for accessing AWS programmatically
- pytz for manipulating timezones
- psycopg2 for accessing Postgres
- lxml for XML/DOM manipulation
- Requests for working over HTTP
- When testing for nulls, always use
if foo is None
rather thanif !foo
sofoo == 0
does not cause bugs. - Always initialize and store datetimes in the UTC timezone. Never use naive datetimes for any reason.
- Always use
with
when accessing resources that need to be closed. - Always access blocking resources (files, databases) as little as possible.
- When accessing a dictionary element that may not exist, use
get()
. For example,os.environ.get('DEPLOYMENT_TARGET', None)
. - Project settings that will be used by both fabric and other code should be isolated in
app_config.py
.fabfile.py
and Django'ssettings.py
should import from this file to prevent duplication. - Imports should be organized into three blocks: stdlib modules, third-party modules and our own modules. Each group should be alphabetized.
- Avoid
from foo import *
. It is the mindkiller.