What is the common header format of Python files?

Viewed 582895

I came across the following header format for Python source files in a document about Python coding guidelines:

#!/usr/bin/env python

"""Foobar.py: Description of what foobar does."""

__author__      = "Barack Obama"
__copyright__   = "Copyright 2009, Planet Earth"

Is this the standard format of headers in the Python world? What other fields/information can I put in the header? Python gurus share your guidelines for good Python source headers :-)

5 Answers

What I use in some project is this line in the first line for Linux machines:

# -*- coding: utf-8 -*-

As a DOC & Author credit, I like simple string in multiline. Here an example from Example Google Style Python Docstrings

# -*- coding: utf-8 -*-
"""Example Google style docstrings.

This module demonstrates documentation as specified by the `Google Python
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
with a section header and a colon followed by a block of indented text.

Example:
    Examples can be given using either the ``Example`` or ``Examples``
    sections. Sections support any reStructuredText formatting, including
    literal blocks::

        $ python example_google.py

Section breaks are created by resuming unindented text. Section breaks
are also implicitly created anytime a new section starts.

Attributes:
    module_level_variable1 (int): Module level variables may be documented in
        either the ``Attributes`` section of the module docstring, or in an
        inline docstring immediately following the variable.

        Either form is acceptable, but the two should not be mixed. Choose
        one convention to document module level variables and be consistent
        with it.

Todo:
    * For module TODOs
    * You have to also use ``sphinx.ext.todo`` extension

.. _Google Python Style Guide:
   http://google.github.io/styleguide/pyguide.html

"""

Also can be nice to add:

        """
        @Author: ...
        @Date: ....
        @Credit: ...
        @Links: ...
        """

Additional Formats

  • Meta-information markup | devguide

    """

          :mod:`parrot` -- Dead parrot access
          ===================================
    
          .. module:: parrot
             :platform: Unix, Windows
             :synopsis: Analyze and reanimate dead parrots.
          .. moduleauthor:: Eric Cleese <eric@python.invalid>
          .. moduleauthor:: John Idle <john@python.invalid>
      """
    
  • /common-header-python

          #!/usr/bin/env python3  Line 1
          # -*- coding: utf-8 -*- Line 2
          #----------------------------------------------------------------------------
          # Created By  : name_of_the_creator   Line 3
          # Created Date: date/month/time ..etc
          # version ='1.0'
          # ---------------------------------------------------------------------------
    
Related