Skip to main content

NDEF (NFC Data Exchange Format) parser and verifier

Project description

Release v0.2 – January 7th, 2020

The ndef modules provides methods for encoding and decoding messages and records in the NDEF format according to NFC Forum technical specification. Its main purpose is to provide comprehensive verification of raw NDEF messages. It can be used to verify messages before writing them to an actual tag.

Available on PyPI.

https://travis-ci.org/kichik/pyndef.svg?branch=master https://badge.fury.io/py/pyndef.svg

Usage

Valid Message

>>> import ndef
>>> message_data = 'D1010F5402656E48656C6C6F20776F726C6421'.decode('hex')
>>> message = ndef.NdefMessage(message_data)
>>> record = message.records[0]
>>> record.tnf
1
>>> record.type
'T'
>>> record.id
>>> record.payload
'\x02enHello world!'
>>>

Invalid Message

>>> import ndef
>>> message_data = '9901050155610123456761'.decode('hex')
>>> message = ndef.NdefMessage(message_data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ndef\ndef.py", line 274, in __init__
    self.verify()
  File "ndef\ndef.py", line 278, in verify
    self._verify_begin_end()
  File "ndef\ndef.py", line 296, in _verify_begin_end
    raise InvalidNdefMessage("last record's ME flag is off")
ndef.ndef.InvalidNdefMessage: last record's ME flag is off
>>>

Create Message

>>> import ndef
>>> text_record = (ndef.TNF_WELL_KNOWN, ndef.RTD_TEXT, 'id', 'hello world')
>>> text_message = ndef.new_message(text_record)
>>> text_raw_ndef = text_message.to_buffer()
>>> text_raw_ndef.encode('hex')
'd9010b0254696468656c6c6f20776f726c64'
>>>

Alternatives

License

Copyright (c) 2014 Amir Szekely

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

   1. The origin of this software must not be misrepresented; you must not
   claim that you wrote the original software. If you use this software
   in a product, an acknowledgment in the product documentation would be
   appreciated but is not required.

   2. Altered source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

   3. This notice may not be removed or altered from any source
   distribution.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ndef-0.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

ndef-0.2-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ndef-0.2.tar.gz.

File metadata

  • Download URL: ndef-0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.7

File hashes

Hashes for ndef-0.2.tar.gz
Algorithm Hash digest
SHA256 7443321f5bd3808a600a8496d40fdc1e2dd2b5fd86283b657a14c209e4ba22d4
MD5 1d18727ff978e126c27d4ce064997c21
BLAKE2b-256 57468f4cf56acab4d9795747d3a3f9285c3d20d7a329879fad96664a2e5690b1

See more details on using hashes here.

File details

Details for the file ndef-0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: ndef-0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.7

File hashes

Hashes for ndef-0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c6d963690a7d8b05afd6c452d5a72c8a36d46c20662b138aea9fdaad6c18a806
MD5 02412d07f4839d5b1037cd4507814408
BLAKE2b-256 f50295e0b1f12b222fb9e6c9bd7479ed5b3ea070ecaabc22fb20d457aea963d6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page