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.2.1

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.2.1
File Size Uploaded Provenance Actions
hashfasta-0.2.1.tar.gz 14.1 kB With provenance Details for hashfasta-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 26.1 kB

Release files / hashfasta-0.2.1.tar.gz

Download URL hashfasta-0.2.1.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5953de2430ce4c866f7c45d126cae162bdf937408e6fe62d50d485d756f36a66
BLAKE2b-256 checksum
How to use checksums
6b627da57593c7534fa04b0f50a7166c400047bbb85c9c694c45151705400aee
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 5, 2026.

Transparency log

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

Download URL hashfasta-0.2.1-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9eac21f371fda7cf1e728db027f1d6402a8dada46c334aa4b675661128b807be
BLAKE2b-256 checksum
How to use checksums
9c9fab5d00f67220dc5701849d5c66de2115cca91e94db309ee7d9ad042ee3dc
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 5, 2026.

Transparency log

Security for hashfasta 0.2.1

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.2.1.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 5, 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