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 "git+https://github.com/linsalrob/HashFASTA#subdirectory=implementations/python"
# 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

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) File (or "-") to gzip HashFASTA; 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.1.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.1.1
File Size Uploaded Provenance Actions
hashfasta-0.1.1.tar.gz 12.5 kB With provenance Details for hashfasta-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 23.1 kB

Release files / hashfasta-0.1.1.tar.gz

Download URL hashfasta-0.1.1.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c387c27207f4d7db8a26fd353c2d21419ac1e9ab033d5ba55a4666dc5f27ad7e
BLAKE2b-256 checksum
How to use checksums
253ff17aebdc913afc7b0547bdfd74c4b1514d4f145cf5a457c10854093f682d
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.1.1-py3-none-any.whl

Download URL hashfasta-0.1.1-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e87e88c9d50a6925e11e00ebc0cb490771251de93d1bc69fe2f55b98aefbfc6
BLAKE2b-256 checksum
How to use checksums
7687de191f7f772ec6073792c11c09d80e4f394a574317f11516f3d3e6c822fb
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.1.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.1.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