← Runnable Projects

阅读中文版本

Python File SHA-256 CLI

Python File SHA-256 — a runnable python project with source, install and run commands, and expected output.

intermediatepythonunverified

Project

py-sha256-file-cli

Entry point: sha.py

Install

python sha.py file.bin

Run

python sha.py sample.bin

Test

pytest sha_test.py

Expected output

Streams a file in chunks through sha256 and prints the hex digest.

Dependencies

  • python >=3.10

Verification evidence

Source reviewed against python standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Python File SHA-256 CLI is a self-contained python command-line program. Streams a file in chunks through sha256 and prints the hex digest.

Install and run

python sha.py file.bin
python sha.py sample.bin

Project structure

py-sha256-file-cli/
├── sha.py
└── README snippet above

Key source

# sha.py
import hashlib, sys
h = hashlib.sha256()
with open(sys.argv[1], "rb") as f:
    for chunk in iter(lambda: f.read(65536), b""):
        h.update(chunk)
print(h.hexdigest())

Testing

pytest sha_test.py

Expected output

When run with the documented command, the program prints:

2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.