afp — Another Fastx Parser
A tiny, dependency-free Python reader/writer for FASTA and FASTQ files
with transparent gzip / bzip2 / zip / zstandard decompression. Standard
library only — zstandard is an optional extra used only for .zst inputs.
The whole module is a single file: afp.py.
Install
Three ways to use it:
Drop the file into your project:
curl -O https://raw.githubusercontent.com/conchoecia/afp/main/afp.py
# put afp.py somewhere on your python path
Or pip-install:
pip install run-afp # core, no extras
pip install "run-afp[zstd]" # also read .zst-compressed files
pip install "run-afp[dev]" # pytest + zstandard for development
The PyPI distribution is run-afp (the bare afp name was already taken).
The import name stays import afp.
Or vendor inside another repo: copy afp.py into your dependencies/
directory, add that directory to sys.path, then import afp.
Quick start
import afp
# Auto-detects FASTA vs FASTQ from the first byte, and gzip/bzip2/zip/zstd
# compression from the file's magic bytes (not its extension).
for rec in afp.parse("reads.fq.gz"):
print(rec.id, len(rec.seq), rec.qual[:10])
for rec in afp.parse("genome.fa"):
print(rec.id, rec.desc, rec.seq[:50])
Force a specific format if needed:
for rec in afp.parse("weirdly_named_file", format="fasta"):
...
# Or use the explicit parsers:
afp.parse_fasta("genome.fa")
afp.parse_fastq("reads.fq")
The Record object
class Record:
id: str # token after '>' or '@', up to first whitespace
seq: str # sequence, newlines stripped
desc: str | None # everything after id on the header line (or None)
qual: str | None # quality string (FASTQ only; None for FASTA)
Records are mutable. You can rewrite record.id in place.
rec.format() # back to FASTA / FASTQ text
rec.format(wrap=80) # FASTA only: wrap sequence at 80 columns
len(rec) # length of seq
"ACGT" in rec # membership on the sequence string
list(rec) # iterate over letters
Writing
afp.write(records, "out.fa") # plain
afp.write(records, "out.fa.gz") # auto-gzip from .gz extension
afp.write(records, "out.fq.gz") # FASTQ if the first record has `qual`
afp.write(records, "out.fa", wrap=80) # wrapped FASTA
Mixing FASTA and FASTQ records in a single output stream is rejected.
Compression helpers
afp.detect_compression("file") # 'gzip' | 'bzip2' | 'zip' | 'zstd' | 'none'
afp.get_open_func("file.gz") # returns gzip.open
detect_compression reads only the first 4 bytes — it's cheap to call.
Why
Built for projects that want to vendor a single Python file rather than pull in a multi-megabyte sequence toolkit, under a permissive license they can carry through to their own code. The whole module is one ~400-line file, no external runtime dependencies, no compiled extensions.
License
MIT — see LICENSE.
Metadata
Release files for run-afp 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| run_afp-0.1.4.tar.gz | 14.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| run_afp-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.6 kB
Release files / run_afp-0.1.4.tar.gz
| Download URL | run_afp-0.1.4.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
177f5e03d44c7686693496b97df9b39e7eaa2200be3b518af2b2d5c52bac452e
|
|
BLAKE2b-256 checksum How to use checksums |
a7c16f0a84050a9a36e3edfb0e5dda5b5374003fcf02dbeaa413f6f9d2e03226
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 13, 2026.
Transparency logRelease files / run_afp-0.1.4-py3-none-any.whl
| Download URL | run_afp-0.1.4-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8911c3b825913d6075ce72354b0d99e93edf46d3aea847842a59c079cdccd14b
|
|
BLAKE2b-256 checksum How to use checksums |
751f63bcaab029c94fc841f605e930c9663981ba2d1b74a6f42f7a534fda0aac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 13, 2026.
Transparency log