Skip to main content

mifarepy

PyPI Version Python Versions PyPI Downloads License GitHub Issues

Overview

mifarepy is a Python library for interfacing with MIFARE® RFID card readers (e.g., PROMAG PCR310U, MF5, MF10) using the GNetPlus® protocol. It provides a clean, object-oriented API for performing common operations such as:

  • Interacting via RS232 and USB-serial interfaces
  • Supporting GNetPlus® commands (Read, Write, Authenticate, Auto Mode, etc.)
  • Reading a card’s serial number (get_sn, wait_for_card)
  • Querying reader firmware version (get_version)
  • Enabling/disabling automatic card events (set_auto_mode, wait_for_card)
  • Authenticating sectors (authenticate_sector)
  • Reading and writing 16‑byte blocks (read_block, write_block)
  • Bulk operations on sectors and arbitrary block mappings (read_sector, write_sector, read_blocks, write_blocks)

Attribution & Original Repository

This project is derived from the original gnetplus.py which is written in Python 2 by Chow Loong Jin & Harish Pillay.

  • Original Repository: gnetplus by harishpillay
  • Original Authors: Chow Loong Jin & Harish Pillay
  • License: This project remains under LGPL v3.0 or later to comply with the original licensing terms.

This version of gnetplus.py includes bug fixes, more features, documentation improvements, and enhanced compatibility.


Supported Hardware

This library is compatible with PROMAG MIFARE® readers, including:

  • PCR310U (USB-based)
  • MF5 OEM Read/Write Module
  • MF10 MIFARE Read/Write Module
  • Other devices using the GNetPlus® protocol

These readers operate at 13.56 MHz and support MIFARE® 1K/4K, Ultra-Light, and PRO cards.


Installation

To install mifarepy, ensure Python 3.6+ is installed, then run:

pip install mifarepy

Or manually include the mifarepy.py file in your project.


Quickstart

from mifarepy.reader import MifareReader

# Initialize the reader on your serial port
reader = MifareReader('/dev/ttyUSB0')

# Enable auto mode and wait for card detection
reader.set_auto_mode(True)
card_sn = reader.wait_for_card(timeout=10)
print('Found card:', card_sn)

# Authenticate sector 1 with the default Key A
default_key = bytes.fromhex('FFFFFFFFFFFF')
reader.authenticate_sector(sector=1, key=default_key, key_type='A')

# Read block 4 and display as hex
block_data = reader.read_block(4)
print('Block 4 data:', block_data)

# Write 16 bytes to block 4
payload = bytes(range(16))
reader.write_block(4, payload)

Communicating with the Reader

Detecting the Device

When plugged into a Linux system (such as Raspberry Pi or Fedora), the reader is detected as:

Prolific Technology, Inc. PL2303 Serial Port

To find the assigned port, check:

dmesg | grep ttyUSB

Example output:

usb 6-1: pl2303 converter now attached to ttyUSB3

This means the device is at /dev/ttyUSB3.


Supported Commands

This library supports the following GNetPlus® protocol commands:

Command Functionality
Polling Check if a reader is connected
Get Version Retrieve firmware version
Logon/Logoff Secure access
Get Serial Number Retrieve MIFARE® card serial number
Read Block Read memory block from MIFARE® 1K card
Write Block Write to a specific block
Authenticate Perform authentication with Key A/Key B
Set Auto Mode Enable/Disable automatic event notifications
Request All Detect multiple cards in the field

For a full list of commands, refer to the * *mifarepy Communication Protocol**.


Example Output

When a card is detected, you will see:

Found card: 0x19593d65
Tap card again.
Found card: 0x19593d65

If no card is found, the script prompts:

Tap card again.

MIFARE® 1K Card Structure

The MIFARE® 1K card consists of 16 sectors, each with 4 blocks (16 bytes each).
Memory layout:

  • Blocks 0-3: Sector 0 (First block stores manufacturer data)
  • Blocks 4-7: Sector 1
  • Blocks 8-11: Sector 2
  • ...
  • Blocks 60-63: Sector 15 (Contains access keys & conditions)

For authentication, use Key A or Key B stored in the last block of each sector.


MIFARE® 1K Authentication & Security

  1. Authenticate before reading/writing.
  2. Use GNetPlus SAVE_KEY command to store keys securely.
  3. Blocks are protected by access conditions.
  4. Keys should not be stored in the same sector as sensitive data.

For further details, refer to:


License

This project is licensed under GNU Lesser General Public License v3.0 or later (LGPL-3.0-or-later).
See COPYING for full details.


Documentation & References

For more details, refer to:

For further information, visit: GIGA-TMS Inc.


Author & Credits

Original Authors:

Adapted & Maintained by:


Metadata

Release files for mifarepy 3.0.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.0.0
File Size Uploaded Provenance
mifarepy-3.0.0.tar.gz 27.0 kB With provenance Details

Built distribution (wheel)

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

Total release size: 47.4 kB

Release files / mifarepy-3.0.0.tar.gz

Download URL mifarepy-3.0.0.tar.gz
Size 27.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d0cf9a579d912acceef8be5ed8887029c9625648069ab1d68f1bc3edd531575c
BLAKE2b-256 checksum
How to use checksums
f21d1e14ff5f00b5f9b0bb2b7fae7cdac9657a95b44a7bfd48c370ecd135d142
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

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

Download URL mifarepy-3.0.0-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
042e33e866d7737890379946e62085d721bba97e2b33532ece6defe1f80e3922
BLAKE2b-256 checksum
How to use checksums
e8c5830c265048c6c39776f81382f68f40fee603774f7d845ab8eafc23b7a0ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 4, 2026.

Transparency log

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mifarepy-3.0.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 Jun 4, 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