AnnotationParser
AnnotationParser is a universal Python library that parses annotation files from various formats (LabelMe, COCO, VOC, etc.) and converts them into a single, unified Shape type.
This approach allows you to read, filter, and save shapes using the same interface, regardless of the original annotation format.
Note: Currently only the LabelMe format is fully implemented and tested. Other formats are planned for future releases (see Limitations & Roadmap).
Table of Contents
- Features
- Usage Examples
- Command-Line Interface (CLI)
- Supported Formats
- Limitations & Roadmap
- Contributing
- Development & Testing
- FAQ / Common Issues
- Author
- License
Features
- Unified API for reading, saving, and filtering shapes in annotation files
- Converts any supported format into a universal
Shapetype for downstream processing - Extensible adapter system for multiple formats (LabelMe, COCO, VOC, ...)
- Functional and OOP usage styles
- High-level filtering and transformation functions for shape objects
- Clean, type-safe, and well-documented codebase
Usage Examples
Installation
Python 3.10+ required
Install with pip (recommended for most users):
pip install annotation-parser
Or, if you have the source code locally:
pip install -e .
Parse and Filter (LabelMe)
from annotation_parser import create, get_shapes_by_label
file = "tests/labelme/labelme_test.json"
parser = create(file, "labelme")
shapes = parser.parse() # tuple of Shape
# Get all shapes with label "person"
persons = get_shapes_by_label(shapes, "person")
print(persons)
Save Annotations
from annotation_parser import save_labelme
save_labelme(shapes, "result.json", backup=True)
Filter by Working Zone, Group Number, Custom Predicate
from annotation_parser import get_shapes_by_wz_number, get_shapes_by_number, filter_shapes
# Filter by working zone (wz_number)
zone2 = get_shapes_by_wz_number(shapes, wz_number=2)
# Filter by instance/group number
group_1 = get_shapes_by_number(shapes, number=1)
# Filter with any condition (lambda)
big_shapes = filter_shapes(shapes, lambda s: hasattr(s, "coords") and len(s.coords) > 3)
OOP Style (Advanced)
from annotation_parser import create
parser = create("tests/labelme/labelme_test.json", "labelme")
shapes = parser.parse()
# You can call parser.save(), parser.parse(), parser.filter_shapes() if needed
Functional Style (shortcut)
from annotation_parser import parse_labelme
shapes = parse_labelme("tests/labelme/labelme_test.json")
Command-Line Interface (CLI) [experimental]
Experimental! Not fully tested. See cli.py for current options.
python cli.py parse --file tests/labelme/labelme_test.json --adapter labelme
python cli.py save --file tests/labelme/labelme_test.json --adapter labelme --out result.json --backup
python cli.py filter --file tests/labelme/labelme_test.json --adapter labelme --label crop
Supported Formats
| Format | Status |
|---|---|
| LabelMe | ✅ Supported |
| COCO | 🕑 Planned |
| Pascal VOC | 🕑 Planned |
| YOLO | 🕑 Planned |
| ... | (Suggest yours!) |
💡 Want to see your annotation format supported? Open an issue or PR — or help me implement a new adapter! Any contribution or feedback on new formats is very welcome.
Limitations & Roadmap
- LabelMe format is currently the only one fully implemented and tested.
- Adapters for other formats (COCO, Pascal VOC, YOLO, etc.) are planned, not yet implemented.
- Standard logging (with configurable log levels and error handling) will be added in future releases.
- The command-line interface (
cli.py) is experimental and not fully tested; improvements needed.
Contributing
- PRs, bug reports, and suggestions are welcome!
- For new formats, contribute an adapter in
src/annotation_parser/adapters/ - All code should be type-checked (
mypy), formatted (black), and covered by tests (pytest).
Development & Testing
-
Install dev dependencies:
poetry install --with dev
-
Run tests:
pytest
FAQ / Common Issues
Q: Why do only LabelMe files work? A: Only the LabelMe adapter is currently implemented. COCO/VOC support is planned.
Q: CLI throws errors or doesn't work as expected?
A: cli.py is not fully tested. Check Limitations & Roadmap and use the Python API for production.
Author
Project: github.com/omigutin/annotation_parser Project Tracker: annotation_parser Project Board Contact: migutin83@yandex.ru
License
MIT License. See LICENSE for details.
Metadata
Release files for annotation-parser 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 | |
|---|---|---|---|
| annotation_parser-0.1.0.tar.gz | 22.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| annotation_parser-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 56.0 kB
Release files / annotation_parser-0.1.0.tar.gz
| Download URL | annotation_parser-0.1.0.tar.gz |
|---|---|
| Size | 22.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c0ab7f44ce5af9d64c2f926887391f54e0ec601d58537d3e652b7a55a78b2637
|
|
BLAKE2b-256 checksum How to use checksums |
ba93f326fbd5404bb4b7e5b20508321bb138c79b6218218e1903e11c82db624e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.11.9 Windows/10
|
Release files / annotation_parser-0.1.0-py3-none-any.whl
| Download URL | annotation_parser-0.1.0-py3-none-any.whl |
|---|---|
| Size | 33.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d3a0514c895ef968505ac12d7c99a613facf5d61ec00e7c3c52aa9b0a1e12ce
|
|
BLAKE2b-256 checksum How to use checksums |
5713efa80c33cc6e55fb226bc1aedb2b97cfa54e3be78bfd821b0be645d9c416
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.11.9 Windows/10
|