Skip to main content

mifarepy

PyPI Version Python Versions PyPI Downloads Tests Coverage Typed License

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.

Terminal demo: mifarepy prints the reader firmware, waits for a card, then shows its UID and reads block 0 of sector 1

📖 Documentation: https://sparkdrago05.github.io/mifarepy/

Install

pip install mifarepy

Requires Python 3.9 or newer. Works on Linux (including Raspberry Pi), Windows and macOS.

Command line

mifarepy info                 # reader, firmware and the card on it
mifarepy watch                # print each card as it is tapped
mifarepy read 1               # show sector 1
mifarepy dump card.json       # save the whole card (.json, .bin/.mfd, .mct)
mifarepy restore card.json    # write it back, or to another card

Add --simulate to try any command without a reader. See the command-line guide.

Quick start

from mifarepy import MifareReader

KEY = bytes.fromhex('FFFFFFFFFFFF')   # factory default key

with MifareReader.auto() as reader:     # or MifareReader('/dev/ttyUSB0') / ('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)))

Features

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()
Command line mifarepy info / scan / watch / read / write / dump / restore; dumps in JSON, raw .bin/.mfd and MIFARE Classic Tool .mct
Zero-config MifareReader.auto() finds the reader; errors name the problem and suggest a fix (AuthenticationError, NoCardError, …)
Testing without hardware Built-in simulated reader and cards, plus pytest fixtures (mifare_reader, mifare_card)
Debugging enable_wire_trace() prints every GNetPlus frame, decoded, with keys hidden
Developer experience Context manager, full type hints (py.typed)

Supported hardware

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.

Documentation

Security

Please report vulnerabilities privately. See SECURITY.md.

Contributing

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 . && mypy

Credits & license

Maintained 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.

Metadata

Release files for mifarepy 3.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mifarepy 3.3.0
File Size Uploaded Provenance Actions
mifarepy-3.3.0.tar.gz 74.7 kB With provenance Details for mifarepy-3.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mifarepy 3.3.0
File Interpreter ABI Platform Actions
mifarepy-3.3.0-py3-none-any.whl Python 3 none any Details for mifarepy-3.3.0-py3-none-any.whl

Total release size: 138.8 kB

Release files / mifarepy-3.3.0.tar.gz

Download URL mifarepy-3.3.0.tar.gz
Size 74.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2be6a64f8a154ce95a08b199351e209929153cebfcbc8cdc2a835629ae806df4
BLAKE2b-256 checksum
How to use checksums
11f66d240b6fd3263b4faca730c088dbb5deba8741e7e9900a41bcf6b46b422e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / mifarepy-3.3.0-py3-none-any.whl

Download URL mifarepy-3.3.0-py3-none-any.whl
Size 64.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12f09d98b4f8a1e08c036b59233a4219188db06e2365058512d6cc2307ae8ae7
BLAKE2b-256 checksum
How to use checksums
340da08837db6f5bb22ae71e74bd7be1ba9c89944e08733df87328699d71c04b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for mifarepy 3.3.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mifarepy-3.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page