Skip to main content

hashfasta (Python)

Python reference implementation of HashFASTA, both a command-line tool and a library. HashFASTA rewrites each FASTA record so that its ID is the SHA-256 of its normalized sequence and keeps the original definition line in brackets:

>sha256_<64 hex digits> [<original definition line>]

Two different sequences that share a source ID get different keys. Identical sequences get the same key, and both records are kept. Output is always gzip. See the specification.

Standard library only. Installing needs Python ≥ 3.10; the code itself also runs on Python 3.6+ straight from a checkout through run_hashfasta.py.

Install

pip install hashfasta
# or, from a checkout
pip install implementations/python

To run from a checkout without installing:

python3 implementations/python/run_hashfasta.py sample.fasta.gz

Command line

hashfasta sample.fna.gz                    # writes sample.hash.fasta.gz
hashfasta sample.fa.bz2 -o out.hash.fasta.gz
zcat x.fa.gz | hashfasta - > x.hash.fasta.gz
python -m hashfasta sample.fasta.xz
hashfasta human.fna.gz --threads 8         # compress the output on 8 threads

Input may be plain FASTA or FASTA compressed with gzip/BGZF, bzip2 or xz. The format is detected from the content, not the file name.

Library

import hashfasta

out = hashfasta.convert("sample.fna.gz")          # "sample.hash.fasta.gz"

for rec in hashfasta.read_hashfasta(out):         # keys are re-verified by default
    print(rec.key, rec.description, len(rec.sequence))

for rec in hashfasta.read_fasta("raw.fa.xz"):     # convert in memory, record by record
    print(rec.key, rec.header)                    # header is bytes, exactly as in the source

hashfasta.sequence_key(hashfasta.normalize_sequence(b"acgt\n"))
# 'sha256_...'
Function Purpose
convert(input, output=None, threads=1) File (or "-") to gzip HashFASTA, compressing on threads threads; returns the output path
read_fasta(source) Yield Record(key, header, sequence) from plain/gz/bz2/xz FASTA
read_hashfasta(source, verify=True) Read a HashFASTA file back, unescaping headers
convert_stream(inp, out) Decompressed stream to uncompressed HashFASTA text
normalize_sequence, sequence_key The normalization and key rules
escape_header, unescape_header Bracket escaping for the provenance field
format_record, iter_records, open_input, default_output_path Lower-level building blocks

Every error is raised as hashfasta.HashFastaError.

Development

python3 -m unittest discover -s implementations/python/tests   # library tests
python3 tests/run_conformance.py python                        # shared conformance suite
python3 -m pip wheel --no-deps -w dist implementations/python  # build a wheel

Releasing to PyPI

.github/workflows/python-package.yml builds, checks and tests the sdist and wheel on every push. To publish:

  1. One-time setup: on PyPI, add a trusted publisher for project hashfasta, repository linsalrob/HashFASTA, workflow python-package.yml and environment pypi. Then create a pypi environment in the GitHub repository settings.
  2. Bump __version__ in src/hashfasta/__init__.py, merge, then push a tag matching it: git tag python-v0.1.0 && git push origin python-v0.1.0.

Metadata

Release files for hashfasta 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hashfasta 0.3.0
File Size Uploaded Provenance Actions
hashfasta-0.3.0.tar.gz 14.1 kB With provenance Details for hashfasta-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hashfasta 0.3.0
File Interpreter ABI Platform Actions
hashfasta-0.3.0-py3-none-any.whl Python 3 none any Details for hashfasta-0.3.0-py3-none-any.whl

Total release size: 26.1 kB

Release files / hashfasta-0.3.0.tar.gz

Download URL hashfasta-0.3.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0ee3145c6a965bb31fb3f40578e8100ba8364925151f3964cd4004e83de7fddf
BLAKE2b-256 checksum
How to use checksums
f28d543694f77d6f060ceb2bcc94e7ff72bcbf9e7e45a6ae1b6235dd0855f1ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / hashfasta-0.3.0-py3-none-any.whl

Download URL hashfasta-0.3.0-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05104b4bccd1569523ab1008cec3c200b5a2c8d184caee4c959e24d45ab7844c
BLAKE2b-256 checksum
How to use checksums
cc8920c5ed21aa0b37612ae9b9e640ce02cb9dda93f640129f31f0a033043b6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Security for hashfasta 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hashfasta-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page