What is the standard way of writing "copyright information" in python code? Should it be inside docstring or in block comments? I could not find it in PEPs.
-
"Standard"? Who would specify such a standard? ISO? IEEE? ANSI? How provides standards for this kind of thing? Copyright is a very localized thing, so what level of standardization are you looking for? US? EU? China? – S.Lott Jan 12 '10 at 13:21
-
7I think the 'standard' here means 'common practice' – Kimvais Jan 12 '10 at 13:58
-
@Kimvais: Interesting read on the question. I wonder what the Author actually meant. – S.Lott Jan 12 '10 at 15:17
-
I thought the question was written clearly enough, especially since the poster mentioned they expected to find this information in the PEP so its implied they are looking for style guidelines. – RTbecard Jan 17 '20 at 17:55
4 Answers
Some projects use module variables like __license__
, as in:
__author__ = "Software Authors Name"
__copyright__ = "Copyright (C) 2004 Author Name"
__license__ = "Public Domain"
__version__ = "1.0"
Seems like a pretty clean solution to me (unless you overdo it and dump epic texts into these variables), but only __version__
seems to be in widespread use, as it is mentioned in PEP 8.

- 1,911
- 1
- 13
- 10
-
Pretty clean, but in most of the organizations, while redistributing a software, copyright is a lot of text. Though I wonder why it is not included in PEP. – Shefali Jan 13 '10 at 05:28
-
As a note for future visitors, this system of ad-hoc module variables has been replaced by standardized distribution metadata. See [PEP 621](https://peps.python.org/pep-0621/), and [Declaring project metadata](https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#declaring-project-metadata) and [`importlib.metadata`](https://docs.python.org/3/library/importlib.metadata.html) from the Python docs. – Brian61354270 Aug 07 '23 at 12:37
# Comment in the beginning of the file
At least python built-in modules do this. (found out by doing grep 'Copyright' /usr/lib64/python2.4/*.py
)

- 38,306
- 16
- 108
- 142
-
3@Shefali was asking for 'the standard way of writing "copyright information"' not whether it necessary to write the information. That's why I think my downvote is justified, while yours looks like a spiteful revenge. – Kimvais Jan 12 '10 at 12:56
We follow the recommendations found (somewhere) on the Software Freedom Law Center's site. Here is an example of a simple GPL'ed file.

- 7,809
- 1
- 30
- 30
-
Looks like there are no guidelines specified for it anywhere in python docs or PEPs, but the above notation is widely used and accepted. Thanks! – Shefali Jan 13 '10 at 05:23
-
Its kinda frowned upon to give links without explanation on SO. Perhaps explain what the example is. In this case, a copyright notice and full license was included at the top of the file using comments (not doc strings). – RTbecard Jan 17 '20 at 18:07
As I know, there is currently no standard way. Each company/organization will have their own template to doc the copyright information. If this is your personal project, then just feel free to doc it in the way you feel most comforable. Adding a LICENSE
file is a very common way for projects with many source files. Even in Python, there is currently no standard on the structure of docstrings.
Python provides a lot of freedom, so just let it be dude ;)

- 147
- 6
-
I get that many may do this differently... but the point of including a license is to avoid legal matters down the road... I don't think _just let it be_ is good advice to give on such things :/ – RTbecard Jan 17 '20 at 18:13