Skip to content

PY (.py)

.py file signature | text/x-python

Safe

Magic Bytes

Offset 0
23 21 2F 62 69 6E 2F 70 79 74 68 6F 6E

Sources: Apache Tika

All Known Signatures

10 signature variants are documented for .py files across multiple sources.

Hex Signature Offset Sources
23 21 2F 62 69 6E 2F 70 79 74 68 6F 6E 0 Apache Tika
23 21 20 2F 62 69 6E 2F 70 79 74 68 6F 6E 0 Apache Tika
65 76 61 6C 20 22 65 78 65 63 20 2F 62 69 6E 2F 70 79 74 68 6F 6E 0 Apache Tika
23 21 2F 75 73 72 2F 62 69 6E 2F 70 79 74 68 6F 6E 0 Apache Tika
23 21 20 2F 75 73 72 2F 62 69 6E 2F 70 79 74 68 6F 6E 0 Apache Tika
65 76 61 6C 20 22 65 78 65 63 20 2F 75 73 72 2F 62 69 6E 2F 70 79 74 68 6F 6E 0 Apache Tika
23 21 2F 75 73 72 2F 6C 6F 63 61 6C 2F 62 69 6E 2F 70 79 74 68 6F 6E 0 Apache Tika
23 21 20 2F 75 73 72 2F 6C 6F 63 61 6C 2F 62 69 6E 2F 70 79 74 68 6F 6E 0 Apache Tika
65 76 61 6C 20 22 65 78 65 63 20 2F 75 73 72 2F 6C 6F 63 61 6C 2F 62 69 6E 2F 70 79 74 68 6F 6E 0 Apache Tika
2F 62 69 6E 2F 65 6E 76 20 70 79 74 68 6F 6E 1 Apache Tika

Extension

.py

MIME Type

text/x-python

Byte Offset

0

Risk Level

Safe

Validation Code

How to validate .py files in Python

Python
def is_py(file_path: str) -> bool:
    """Check if file is a valid PY by magic bytes."""
    signature = bytes([0x23, 0x21, 0x2F, 0x62, 0x69, 0x6E, 0x2F, 0x70, 0x79, 0x74, 0x68, 0x6F, 0x6E])
    with open(file_path, "rb") as f:
        return f.read(13) == signature

How to validate .py files in Node.js

Node.js
function isPY(buffer: Buffer): boolean {
  const signature = Buffer.from([0x23, 0x21, 0x2F, 0x62, 0x69, 0x6E, 0x2F, 0x70, 0x79, 0x74, 0x68, 0x6F, 0x6E]);
  return buffer.subarray(0, 13).equals(signature);
}

How to validate .py files in Go

Go
func IsPY(data []byte) bool {
    signature := []byte{0x23, 0x21, 0x2F, 0x62, 0x69, 0x6E, 0x2F, 0x70, 0x79, 0x74, 0x68, 0x6F, 0x6E}
    if len(data) < 13 {
        return false
    }
    return bytes.Equal(data[:13], signature)
}

API Endpoint

GET /api/v1/py
curl https://filesignature.org/api/v1/py

See the full API documentation for all endpoints and parameters.

Frequently Asked Questions

What is a .py file?

A .py file is a PY file.

What are the magic bytes for .py files?

The magic bytes for PY files are 23 21 2F 62 69 6E 2F 70 79 74 68 6F 6E at byte offset 0. These bytes uniquely identify the file format regardless of the file extension.

How do I validate a .py file?

To validate a .py file, read the first bytes of the file and compare them against the known magic bytes (23 21 2F 62 69 6E 2F 70 79 74 68 6F 6E) at offset 0. This is more reliable than checking the file extension alone, as extensions can be renamed.

What is the MIME type for .py files?

The primary MIME type for .py files is text/x-python.

Is it safe to open .py files?

PY (.py) files are generally safe to open. They are classified as low risk because they primarily contain data rather than executable code. However, always ensure files come from a trusted source.