gtfparse
gtfparse reads GTF (Gene Transfer Format) annotation files, such as those from Ensembl and GENCODE, into pandas DataFrames: one row per feature, with attributes such as gene and transcript IDs expanded into columns. It can also write a table back to GTF. In the OpenVax tools, PyEnsembl uses it to read Ensembl and custom annotations before indexing them.
Install
python -m pip install gtfparse
Python 3.11 or later is required. gtfparse depends on pandas and PyArrow; for
optional Polars output, install gtfparse[polars].
Quick start
This small artificial GTF runs without a download. Replace the stream with your annotation filename when working with a real dataset.
from io import StringIO
from gtfparse import read_gtf
annotation = StringIO(
'1\texample\tgene\t101\t200\t.\t+\t.\tgene_id "g1"; gene_name "EXAMPLE";\n'
'1\texample\texon\t101\t150\t.\t+\t.\tgene_id "g1"; transcript_id "t1";\n'
)
features = read_gtf(annotation)
genes = features.loc[features["feature"] == "gene"]
print(genes["gene_name"].tolist())
for row in features.itertuples():
print(row.feature, row.seqname, row.start, row.end, row.gene_id)
['EXAMPLE']
gene 1 101 200 g1
exon 1 101 150 g1
feature identifies the row type. seqname is the chromosome or contig name;
it is not the gene ID. The ninth GTF field supplies attributes such as
gene_id, gene_name and transcript_id. Coordinates stay one-based and
inclusive, as in the file.
Documentation
The guides are Markdown files in
docs/. In reading order:
- Filter and write annotations: select chromosomes and features, write GTF and read numeric attributes.
- Report parsing progress with your own progress bar.
- Version 3 migration: pandas by default, and optional Polars output.
- API reference for every public function.
To build the documentation locally, run
python -m pip install -r requirements-docs.txt and ./docs.sh.
python scripts/check_docs_examples.py checks the printed example output.
Development
python -m pip install -e ".[dev]"
./lint.sh # ruff check and ruff format --check
./test.sh # pytest with coverage
./format.sh applies ruff formatting.
License
Apache 2.0; see LICENSE.
Metadata
Release files for gtfparse 3.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 |
|---|---|---|---|---|
| gtfparse-3.1.0.tar.gz | 144.4 kB | Without provenance | Details for gtfparse-3.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gtfparse-3.1.0-py3-none-any.whl | Python 3 | none | any | Details for gtfparse-3.1.0-py3-none-any.whl |
Total release size: 169.2 kB
Release files / gtfparse-3.1.0.tar.gz
| Download URL | gtfparse-3.1.0.tar.gz |
|---|---|
| Size | 144.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7000c223c0116874fe853ddad3877f137fa40a81b7dc6fb97c11828b52466f9f
|
|
BLAKE2b-256 checksum How to use checksums |
2b17151e02b62a1df8d1e4e7866ca1426e65768a31535503f6405f22454ef27d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / gtfparse-3.1.0-py3-none-any.whl
| Download URL | gtfparse-3.1.0-py3-none-any.whl |
|---|---|
| Size | 24.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e1689417c85d6ad6159715eea6a95ca56167174b9f648119e37fa685cdbee6c
|
|
BLAKE2b-256 checksum How to use checksums |
4f5987bab9dba871004b683ca114656423e73387ae01d9d3f2420133a4fbed11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for gtfparse 3.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.