Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
What is the common header format of Python files?
Next article icon

What is the common header format of Python files?

Last Updated : 21 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

When writing Python scripts, it's important to maintain a clean and well-documented codebase. One of the key practices for achieving this is adding a header to each Python file. The header provides essential information about the script, such as its functionality, author and dependencies, which can be especially useful for collaboration and code maintenance.

Key components of a Python file header

Let’s understand the key components of a Python file header. Each part provides essential information about the script. Here's how to create one step by step:

1. Shebang Line: The shebang line at the top of the file tells the operating system which interpreter to use when running the script. It's primarily used in Unix-like operating systems.

#!/usr/bin/env python3

2. Encoding Declaration: It specifies the encoding used in the Python source file, which is important when the file contains non-ASCII characters. This line is typically placed at the top of the file, immediately following the shebang line (if present).

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

3. Docstring: It is a multi-line string that provides a detailed description of the script/module. It usually includes:

  • File Name: The name of the script.
  • Author: The creator of the file.
  • Created/Updated Date: When the file was created or last updated.
  • Version: The current version of the script.
  • Description: A brief overview of the file’s purpose.

"""
Filename: myscript.py
Author: John Doe
Date: 2024-04-17
Version: 1.0
Description: This script performs basic file manipulation.
"""

4. Metadata: Additional information such as license details, contact information and external dependencies can also be included in the header. This is helpful for managing the script’s usage, distribution and collaboration.

"""
License: MIT License
Contact: [email protected]
Dependencies: os, sys
"""

Examples of creating headers

Example 1: In this example, we are creating a basic header with essential details like the filename, author, creation date and a brief description of the script's purpose.

Python
# Filename: basic_header.py # Author: Jane Doe # Created: 2024-06-19 # Description: This script has a basic header format.  import os import sys  print("Hello World!") 

Output

Hello World!

Example 2: In this example, we are adding more details to the header, including the shebang line, encoding declaration, and additional information like the version and description of the script.

Python
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Filename: detailed_header.py Author: John Doe Date: 2024-06-11 Version: 1.0 Description: This script has a detailed header format. """  import os import sys  print("Hello World!") 

Output

Hello World!

Example 3: In this example, we are using an extended header format that includes the shebang line, encoding declaration and more detailed information like the script's license, contact information and dependencies.

Python
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Filename: extended_header.py Author: Jane Smith Date: 2024-06-11 Version: 1.0 Description:      This script demonstrates a detailed      header format with additional metadata.  License: MIT License Contact: [email protected] Dependencies: os, sys """  import os import sys  print("Hello World!") 

Output

Hello World!

Next Article
What is the common header format of Python files?

S

sai_teja_anantha
Improve
Article Tags :
  • Python
  • python-utility
Practice Tags :
  • python

Similar Reads

    What is the use of Python -m flag?
    Python, a versatile and widely used programming language, provides a plethora of features and command-line options to facilitate various tasks. One such option that might pique your interest is the -m switch. In this article, we will explore what Python -m is and how it can be used, accompanied by f
    2 min read
    Working with Headers And Footers in Python .docx Module
    Prerequisite: Working with .docx module Word documents contain formatted text wrapped within three object levels. The Lowest level-run objects, middle level-paragraph objects, and highest level-document objects. So, we cannot work with these documents using normal text editors. But, we can manipulat
    6 min read
    How to write Comments in Python3?
    Comments are text notes added to the program to provide explanatory information about the source code. They are used in a programming language to document the program and remind programmers of what tricky things they just did with the code and also help the later generation for understanding and mai
    4 min read
    Formatting containers using format() in Python
    Let us see how to format containers that were accessed through __getitem__ or getattr() using the format() method in Python. Accessing containers that support __getitem__a) For Dictionaries Python3 # creating a dictionary founder = {'Apple': 'Steve Jobs', 'Microsoft': 'Bill Gates'} # formatting prin
    1 min read
    Python requests - POST request with headers and body
    HTTP headers let the client and the server pass additional information with an HTTP request or response. All the headers are case-insensitive, headers fields are separated by colon, key-value pairs in clear-text string format.Request with headersRequests do not change its behavior at all based on wh
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences