diff --git a/PyNDN/Data.py b/PyNDN/Data.py
new file mode 100644
index 0000000..8d92201
--- /dev/null
+++ b/PyNDN/Data.py
@@ -0,0 +1,126 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+# 
+# Copyright (c) 2011-2013, Regents of the University of California
+#                          Alexander Afanasyev
+# 
+# GNU 3.0 license, See the LICENSE file for more information
+# 
+# Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+# 
+
+#
+# Based on PyCCN code, copyrighted and licensed as follows
+#
+# Copyright (c) 2011-2013, Regents of the University of California
+# BSD license, See the COPYING file for more information
+# Written by: Derek Kulinski <takeda@takeda.tk>
+#             Jeff Burke <jburke@ucla.edu>
+#
+
+import ns.ndnSIM
+from Name import Name
+
+class Data (object):
+    _data = None
+
+    def __init__(self,
+                 name = None, content = None, signed_info = None,
+                 data = None):
+        if data:
+            if type (data) is Data:
+                self._data = data._data
+            elif type (data) is ns.ndnSIM.ndn.ContentObject:
+                self._data = data
+            else:
+                raise TypeError ("Invalid type supplied for 'data' parameter [%s]" % type (data))
+        else:
+            self._data = ns.ndnSIM.ndn.ContentObject ()
+
+            self.name = name
+            self.content = content
+            self.signedInfo = signed_info or SignedInfo ()
+
+    def sign (self, key):
+        """There is no actual signing in ndnSIM for now, but we will assign signature bits based on key"""
+        self._data.SetSignature (key.fakeKey)
+
+    def verify_signature (self, key):
+        """There is no actual signing in ndnSIM for now, but we will check if signature matches the key"""
+        return self._data.GetSignature () == key.fakeKey
+
+    def __getattr__ (self, name):
+        if name == "signedInfo":
+            return object.__getattr__ (self, name)
+        elif name == "name":
+            return Name (self._data.GetName ())
+        elif name == "scope":
+            return self._data.GetScope ()
+        elif name == "interestLifetime":
+            return self._data.GetInterestLifetime ().ToDouble (ns.core.Time.S)
+        else:
+            return self._data.__getattribute__ (name)
+
+    def __setattr__(self, name, value):
+        if name == "_data":
+            return object.__setattr__ (self, name, value)
+        elif name == 'signedInfo':
+            if not value:
+                return
+            if type (value) is SignedInfo:
+                object.__setattr__ (self, name, value)
+                
+                if value.timestamp:
+                    pass
+                if value.freshnessSeconds:
+                    pass
+                if value.keyLocator:
+                    pass
+            else:
+                raise TypeError ("signedInfo can be assigned either None or SignedInfo object, [%s] supplied" % type (value))
+        elif name == "name":
+            if not value:
+                return self._data.SetName (ns.ndnSIM.ndn.Name ())
+            elif type (value) is Name:
+                return self._data.SetName (value._name)
+            elif type (value) is ns.ndnSIM.ndn.Name:
+                return self._data.SetName (value)
+            elif type (value) is str:
+                return self._data.SetName (ns.ndnSIM.ndn.Name (value))
+            else:
+                raise ValueError ("Invalid name parameter")
+        elif name == "content":
+            if not value:
+                pkt = ns.network.Packet ()
+                self._data.SetPayload (pkt)
+            else:
+                pkt = ns.network.Packet (bytes (value))
+                self._data.SetPayload (pkt)
+        else:
+            raise NameError ("Unknown attribute [%s]" % name)
+
+    def __repr__(self):
+        return "ndn.Data(%s)" % str (self._data)
+
+class SignedInfo (object):
+    def __init__(self, keyLocator = None, freshness = None, timestamp = None):
+
+        self.timestamp = timestamp
+        self.freshnessSeconds = freshness
+        self.keyLocator = keyLocator
+
+    def __repr__(self):
+        args = []
+
+        if self.keyLocator is not None:
+            args += ["keyLocator=%r" % self.keyLocator]
+        if self.freshnessSeconds is not None:
+            args += ["freshness=%r" % self.freshnessSeconds]
+        if self.timeStamp is not None:
+            args += ["timestamp=%r" % self.timestamp]
+
+        return "ndn.SignedInfo(%s)" % ", ".join(args)
+
+class ContentObject (Data):
+    """For backwards compatibility"""
+    pass
+
