Git Product home page Git Product logo

pyndef's Introduction

Python Module for NFC Data Exchange Format (NDEF)

Release v0.1 -- February 22nd, 2014

The ndef modules provides methods for creating and parsing 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.

image

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 "ndefndef.py", line 274, in __init__ self.verify() File "ndefndef.py", line 278, in verify self._verify_begin_end() File "ndefndef.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.

pyndef's People

Contributors

kichik avatar

Watchers

James Cloos avatar Philippe Ombredanne avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.