Skip to main content

protfasta

PyPI version Python versions Documentation Status License: MIT Last commit Open issues Stars Downloads

Release 0.1.21 (July 2026)

Overview

protfasta - a robust parser for protein-based FASTA files.

Documentation

For all documentation see https://protfasta.readthedocs.io/en/latest/.

For code see https://github.com/holehouse-lab/protfasta.

Installation

protfasta has been tested on Linux and macOS. It should also work on Windows but we haven't tested it there yet.

protfasta can be downloaded and installed directly from PyPI using pip:

pip install protfasta

If this has worked, the pfasta command-line tool should be available from the command-line

pfasta --help

And you're done. This also means you can now import and use protfasta in your Python workflow.

Simple example

import protfasta

# sequences is now a dictionary where keys are FASTA headers and values are sequences.
sequences = protfasta.read_fasta('inputfile.fasta')

Errors and help

For bug reports or errors please raise an issue on this github repository (see the Issues tab at the top).

Changelog

  • 0.1.20 and 0.1.21 (July 2026) - Change defaults for protfasta.read_fasta_stream(...)

    • Previously the default options for protfasta.read_fasta_stream(...) led to a small O(N) memory growth due to duplicate record sanity checking. We have now changed the default behavior to not check for duplicates, ensuring protfasta.read_fasta_stream(...) is truly memory flat. We also include a warning if options are passed to protfasta.read_fasta_stream(...) that will not yeild a flat memory implementation. Note that even if this is the case, the memory footprint here remains much smaller than for the read_fasta(...) implementation.
    • Update to readme (for 0.1.21)
  • 0.1.19 (July 2026) - Streaming reads with full sanitization.

    • New protfasta.read_fasta_stream(...) - a streaming counterpart to read_fasta with an identical signature. It returns a generator that yields (header, sequence) tuples (or [header, sequence] lists with return_list=True) one record at a time, applying the same sanitization pipeline as read_fasta (duplicate handling, invalid-residue handling, alignment support, custom header parsing). Peak memory stays bounded to roughly one record, so files larger than RAM can be processed in a single pass. Sanitized output can be teed to disk as it streams via output_filename.
    • Breaking change: removed the public protfasta.iter_fasta generator that was introduced in 0.1.18. read_fasta_stream supersedes it - it provides the same streaming access plus the full sanitization pipeline. For the closest drop-in equivalent (streaming with no checks), use read_fasta_stream(f, expect_unique_header=False, duplicate_record_action='ignore', invalid_sequence_action='ignore'); or just read_fasta_stream(f) to additionally gain header-uniqueness, duplicate, and invalid-residue validation.
    • Added a dedicated read_fasta_stream documentation page and worked examples, including guidance on when to use read_fasta_stream vs read_fasta.
    • Test suite expanded with 21 new tests covering the streaming parser.
  • 0.1.18 (April 2026) - Performance overhaul for large FASTA files (hundreds of millions of sequences).

    • read_fasta now streams the input file instead of reading it entirely into memory with readlines() — peak memory is now O(single record) rather than O(file size).
    • New protfasta.iter_fasta(filename, header_parser=None) generator for memory-bounded streaming access to (header, sequence) pairs from files that don't fit in RAM.
    • Core parser rewritten to use list-of-parts + ''.join() instead of quadratic string concatenation, and to skip header-uniqueness tracking entirely when expect_unique_header=False.
    • convert_to_valid / invalid-residue handling now uses a pre-built str.translate table (single C-level pass) instead of a chained str.replace loop — typically 5–20× faster.
    • check_sequence_is_valid now uses frozenset membership instead of list-based in scans.
    • Duplicate-detection utilities (fail_on_duplicates, remove_duplicates, fail_on_duplicate_sequences, remove_duplicate_sequences) now store 16-byte blake2b digests instead of full sequences in their lookup structures, dramatically reducing peak memory for files with long sequences.
    • write_fasta replaced its per-residue fh.write() loop with chunked slice writes and opens the output with a 1 MiB buffer — roughly two orders of magnitude faster on large files.
    • All existing behavior and the full test suite (239 tests) are preserved.
  • 0.1.16 - 0.1.17 - skipped...

  • 0.1.14 and 0.1.15 (October 2024) - Re-wrote build chain and versioning to use pyproject.toml and versioningit. protfasta should now support Python beyond 3.12. About bloody time.

    • Added --version flag to pfasta
    • Messed around a bit with tags to ensure we had a tagged version compatible with them.
  • 0.1.13 (January 2023) - Added upper limit of Python 3.11 to accomodate clash between versioneer and Python 3.12. Ultimately we'll move to versioningit for release versioning (as we have done internally) but need to make sure we have a robust protocol for this switch and then do this for ALL tools....

  • 0.1.12 (March 2023) - integrated in check_header_parser flag via pull request from the amazing Friedlab !

  • Added in append_to_fasta flag so you can append to an existing FASTA file (thanks Ryan!)

  • 0.1.11 (Sept 17th 2022) - re-wrote code for checking duplicate sequence to make it O(1) instead of O(n) for number of sequences (:-/) and added convert-remove option for invalid_sequences

  • 0.1.9 (Sept 12th 2021) - added in robustness for whitespace in sequence files, which, bizarrely, was not present (i.e. added as an invalid residue type but can now be converted).

Copyright

Copyright (c) 2020-2026, Alex Holehouse - Holehouse lab. protfasta is released under the MIT license. The codebase is well structured and relatively simple, lending it to feature addition. We welcome pull-requests assuming contributed code maintains an appropriate level of clarity and robustness.

Acknowledgements

Many of the software-engineering tools and approaches used in the development of protfasta come from resources developed by the Molecular Sciences Software Institute.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

protfasta-0.1.22.tar.gz (132.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

protfasta-0.1.22-py3-none-any.whl (139.9 kB view details)

Uploaded Python 3

File details

Details for the file protfasta-0.1.22.tar.gz.

File metadata

  • Download URL: protfasta-0.1.22.tar.gz
  • Upload date:
  • Size: 132.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for protfasta-0.1.22.tar.gz
Algorithm Hash digest
SHA256 93f1fecb5ba532c279f2a5c59577cc08541387f62309184fc2cd00a20f7dd0e1
MD5 17b6724f0a7c386ff931718384209a6b
BLAKE2b-256 72bf7b682a02ca5868ada5a5642c1ee97b343bbe39a289d02a563b258f53a78a

See more details on using hashes here.

File details

Details for the file protfasta-0.1.22-py3-none-any.whl.

File metadata

  • Download URL: protfasta-0.1.22-py3-none-any.whl
  • Upload date:
  • Size: 139.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for protfasta-0.1.22-py3-none-any.whl
Algorithm Hash digest
SHA256 666ab2a4f8a83d6f5927d13e6eb5c77d52d003e6e7e39c36a5e1d91ac4674119
MD5 cda6a48b2935e6a50294f9f3d8907274
BLAKE2b-256 d0bfb9a166432caf685c5d3a9983794267dc3c15e6b1c7f97225b42e87eaeec4

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.23

2 files

This release

0.1.22 This release

2 files

0.1.21

2 files

0.1.20

2 files

0.1.19

2 files

0.1.18

1 file

0.1.15.2

1 file

0.1.15.1

1 file

0.1.13

1 file

0.1.12

1 file

0.1.11

1 file

0.1.10

1 file

0.1.9

1 file

0.1.8

1 file

0.1.7

1 file

0.1.5

1 file

0.1.4.1

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page