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.9; 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:
- One-time setup: on PyPI, add a trusted publisher for project
hashfasta, repositorylinsalrob/HashFASTA, workflowpython-package.ymland environmentpypi. Then create apypienvironment in the GitHub repository settings. - Bump
__version__insrc/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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hashfasta-0.1.0.tar.gz | 12.5 kB | With provenance | Details for hashfasta-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hashfasta-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for hashfasta-0.1.0-py3-none-any.whl |
Total release size: 23.1 kB
Release files / hashfasta-0.1.0.tar.gz
| Download URL | hashfasta-0.1.0.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19510f7752b74008322e38e5c91bf9fd1f5b1d7f45678626e6993084d4bdc75a
|
|
BLAKE2b-256 checksum How to use checksums |
356b6e636687d741f94e56744076aa94de2be6e3ab64f90daa91db7623162ee1
|
| 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 logRelease files / hashfasta-0.1.0-py3-none-any.whl
| Download URL | hashfasta-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ecbcb5ca9422ead0805e6d0be7dfe268b42fd8dcc743a419fc5a1cb3b711261f
|
|
BLAKE2b-256 checksum How to use checksums |
c2848619435a7798dfabdab21165513d775f0622617a878e1af2634577cc19fc
|
| 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 logSecurity for hashfasta 0.1.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.
Attestation for hashfasta-0.1.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 5, 2026.
Transparency logA 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.