Another Fastx Parser — tiny, dependency-free FASTA/FASTQ reader with transparent gzip/bzip2/zip/zstd decompression.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file run_afp-0.1.4.tar.gz.
File metadata
- Download URL: run_afp-0.1.4.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
177f5e03d44c7686693496b97df9b39e7eaa2200be3b518af2b2d5c52bac452e
|
|
| MD5 |
3e68422d7d38652be8d55a7b9aa43056
|
|
| BLAKE2b-256 |
a7c16f0a84050a9a36e3edfb0e5dda5b5374003fcf02dbeaa413f6f9d2e03226
|
Provenance
The following attestation bundles were made for run_afp-0.1.4.tar.gz:
Publisher:
publish.yml on conchoecia/afp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
run_afp-0.1.4.tar.gz -
Subject digest:
177f5e03d44c7686693496b97df9b39e7eaa2200be3b518af2b2d5c52bac452e - Sigstore transparency entry: 1523385289
- Sigstore integration time:
-
Permalink:
conchoecia/afp@2646b97a1c7fc9e8f0e536c608061cbe8b43e1b5 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/conchoecia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2646b97a1c7fc9e8f0e536c608061cbe8b43e1b5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file run_afp-0.1.4-py3-none-any.whl.
File metadata
- Download URL: run_afp-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8911c3b825913d6075ce72354b0d99e93edf46d3aea847842a59c079cdccd14b
|
|
| MD5 |
70c50768f1fa6a8bc2a536b4c3d0bef7
|
|
| BLAKE2b-256 |
751f63bcaab029c94fc841f605e930c9663981ba2d1b74a6f42f7a534fda0aac
|
Provenance
The following attestation bundles were made for run_afp-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on conchoecia/afp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
run_afp-0.1.4-py3-none-any.whl -
Subject digest:
8911c3b825913d6075ce72354b0d99e93edf46d3aea847842a59c079cdccd14b - Sigstore transparency entry: 1523385317
- Sigstore integration time:
-
Permalink:
conchoecia/afp@2646b97a1c7fc9e8f0e536c608061cbe8b43e1b5 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/conchoecia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2646b97a1c7fc9e8f0e536c608061cbe8b43e1b5 -
Trigger Event:
release
-
Statement type: