Skip to main content

Python File Audit

PythonCodeAudit Badge OpenSSF Best Practices PyPI - Version Documentation License

File Audit – Simplify Python Secure Programming by adding one line! Build secure Python applications by default. Validate files before you use them.

Python File Audit protects you from using insecure files and file-based attacks with a comprehensive set of safety checks.

Safety Checks

  • File size limit – Prevents oversized files from being processed
  • GZip decompression ratio – Guards against decompression bombs
  • Tar member count – Limits the number of entries inside tar archives
  • Total extracted size – Caps the overall size of extracted content
  • Individual file size – Enforces a maximum size per extracted file
  • Path traversal protection – Blocks ../ and absolute path tricks
  • Reject symlinks – Disallows symbolic links
  • Reject hardlinks – Disallows hard links
  • Reject device files – Blocks device nodes
  • Reject FIFOs – Blocks named pipes
  • Filename length – Enforces a maximum filename length
  • Directory depth – Limits how deeply nested directories can be

These checks can be used via a simple API or by adding a decorator — without changing your existing code.

Installation

pip install fileaudit

Safety Checks

  • File size limit – Prevents oversized files from being processed
  • GZip decompression ratio – Guards against decompression bombs
  • Tar member count – Limits the number of entries inside tar archives
  • Total extracted size – Caps the overall size of extracted content
  • Individual file size – Enforces a maximum size per extracted file
  • Path traversal protection – Blocks ../ and absolute path tricks
  • Reject symlinks – Disallows symbolic links
  • Reject hardlinks – Disallows hard links
  • Reject device files – Blocks device nodes
  • Reject FIFOs – Blocks named pipes
  • Filename length – Enforces a maximum filename length
  • Directory depth – Limits how deeply nested directories can be

These checks can be used via a simple API or by adding a decorator — without changing your existing code.

Installation

pip install fileaudit

Usage

API / Decorator (CSV example)

Validate a local CSV file:

validate_csv("data.csv")

Validate a CSV file from a URL:

validate_csv("https://example.com/data.csv")

Use as a decorator (first function argument is treated as the CSV path):

@validate_csv
def process_csv(csv_path):
    ...

Use as a decorator with default validation options:

@validate_csv()
def process_csv(csv_path):
    ...

Specify the decorated function argument that contains the CSV path:

@validate_csv("input_file")
def process_csv(input_file):
    ...

Configure validation limits:

@validate_csv(
    max_file_size=10 * 1024 * 1024,
    max_rows=10_000,
    max_columns=50,
)
def process_csv(csv_path):
    ...

CLI

You can also inspect a file directly from the command line:

fileaudit path/to/file

Supported File Types

File types are auto-detected from the extension:

Extension Description
csv CSV files
gz GZIP files
json JSON files
py Python source files
tar TAR archives
tar-gz TAR.GZ archives
tgz TAR.GZ archives
xml XML files
zip ZIP archives

Python File Audit helps you validate files before they reach your application logic, reducing the risk of common file-based attacks.

Contributing

All contributions are welcome! Think of corrections on the documentation, code or more and better tests.

Simple Guidelines:

  • Questions, Feature Requests, Bug Reports please use on the Github Issue Tracker.

Pull Requests are welcome!

When you contribute to FileAudit, your contributions are made under the same license as the file you are working on.

[!NOTE] This is an open community driven project. Contributors will be mentioned in the documentation.

We adopt the Collective Code Construction Contract(C4) to streamline collaboration.

License

fileaudit is distributed under the terms of the GPL-3.0-or-later license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fileaudit-0.2.0.tar.gz (10.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fileaudit-0.2.0-py3-none-any.whl (60.5 kB view details)

Uploaded Python 3

File details

Details for the file fileaudit-0.2.0.tar.gz.

File metadata

  • Download URL: fileaudit-0.2.0.tar.gz
  • Upload date:
  • Size: 10.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.18.0 {"ci":null,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.14.6"},"installer":{"name":"hatch","version":"1.18.0"},"openssl_version":"OpenSSL 3.6.3 9 Jun 2026","python":"3.14.6","system":{"name":"Linux","release":"6.8.0-137-generic"}} HTTPX2/2.10.0

File hashes

Hashes for fileaudit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 faf0ffa8fe6e578b1bfe2a4b8ccd80bc323f1f8f25cce046ae0a7a623fadebda
MD5 42e224c4c29a6b9e6145d03901acd834
BLAKE2b-256 f6ff19af975fb52816d569fbf575dc863c0e3096187ca3dfe06a3a16119e81ad

See more details on using hashes here.

File details

Details for the file fileaudit-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fileaudit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 60.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.18.0 {"ci":null,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.14.6"},"installer":{"name":"hatch","version":"1.18.0"},"openssl_version":"OpenSSL 3.6.3 9 Jun 2026","python":"3.14.6","system":{"name":"Linux","release":"6.8.0-137-generic"}} HTTPX2/2.10.0

File hashes

Hashes for fileaudit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b847a66d609fb4f34a04e34f14f00770a1b43913777ca9ea0c7faf96802c566
MD5 da0d8ab48fdc0f0cfb36b36894f3d1be
BLAKE2b-256 5497c6d5ad1a69f362706f11499d11b43aac36611f7174645cd6d18669177f79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page