Read, write and manage MIFARE® Classic cards from Python with PROMAG and
other GIGA-TMS readers that speak the GNetPlus® serial protocol.
Typed, tested, and its only dependency is pyserial.
📖 Documentation: https://sparkdrago05.github.io/mifarepy/
pip install mifarepyRequires Python 3.9 or newer. Works on Linux (including Raspberry Pi), Windows and macOS.
from mifarepy import MifareReader
KEY = bytes.fromhex('FFFFFFFFFFFF') # factory default key
with MifareReader('/dev/ttyUSB0') as reader: # Windows: 'COM3'
print('Reader:', reader.get_version())
print('Card UID:', reader.get_uid()) # e.g. '0xEDCEF8C3'
reader.authenticate_sector(1, KEY)
print('Block 0:', reader.read_block(0)) # 32-char hex string
reader.write_block(0, bytes(range(16)))| Card detection | get_uid(), scan_tag(), is_card_present(), wait_for_card(), wait_for_card_async(), multi-card request_all() |
| Authentication | authenticate_sector() with Key A or B, authenticate_sector_cached() |
| Block I/O | read_block(), write_block(), read_sector(), write_sector() (never touches sector trailers) |
| Bulk I/O | read_blocks() / write_blocks() across sectors with per-sector SectorAuth keys |
| Value blocks | create_value_block(), read_value(), increment_value(), decrement_value(), transfer(), restore(), with native, verified transfer/restore |
| Card layout | MIFARE Classic 1K and 4K, including the 16-block sectors 32–39; mifarepy.layout helpers for block arithmetic |
| Reader control | ping(), get_version(), set_auto_mode(), halt(), rf_power() |
| Developer experience | Context manager, full type hints (py.typed), typed errors with readable NAK codes |
| Reader | Connection |
|---|---|
| PROMAG PCR310U | USB (PL2303 USB-serial) |
| PROMAG MF5 / MF10 | RS-232 / TTL serial |
| Other GNetPlus® readers | Serial |
Cards: MIFARE Classic 1K and 4K (13.56 MHz, ISO/IEC 14443 A). See Hardware & setup for finding the port, Linux permissions and troubleshooting.
- Usage guide: every feature with examples
- MIFARE Classic primer: sectors, keys, access bits, value blocks
- GNetPlus protocol reference: frame format, CRC, commands, error codes
- API reference
- Examples: nine runnable scripts
Please report vulnerabilities privately. See SECURITY.md.
Bug reports, ideas and pull requests are welcome. See the contributing guide.
git clone https://github.com/SparkDrago05/mifarepy.git && cd mifarepy
pip install -e ".[dev]"
pytest && ruff check . && mypyMaintained by Spark Drago (@SparkDrago05).
mifarepy began as a Python 3 port of gnetplus (© 2013 Red Hat Inc., by Chow Loong Jin and Harish Pillay) and has since grown into a separate library.
Licensed under the GNU Lesser General Public License v3.0 or later. See LICENSE and COPYING.
MIFARE® is a registered trademark of NXP B.V., and GNetPlus® is a trademark of GIGA-TMS Inc. mifarepy is an independent project and is not affiliated with either company.
