<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>The urdflib Library for MicroPython: Manipulating RDF on Constrained Devices</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Mohsen Hadavi</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Maxime Lefrançois</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Mines Saint-Étienne</institution>
          ,
          <addr-line>42023 Saint-Étienne</addr-line>
          <country country="FR">France</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Mines Saint-Étienne, Univ Clermont Auvergne, INP Clermont Auvergne</institution>
          ,
          <addr-line>CNRS, UMR 6158 LIMOS, F - 42023 Saint-Étienne</addr-line>
          <country country="FR">France</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>This demonstration paper introduces the urdflib library for MicroPython, which facilitates the development of RDF manipulation programs for embedded devices that run MicroPython, and additionally ensures the API is compatible with the widely used RDFLib Python library. The library is openly available on GitHub, a demo is presented, and the performances of the library are evaluated on the Unix and the ESP32 ports of MicroPython. urdflib performs better than RDFLib on the Unix port.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Semantic Web of Things</kwd>
        <kwd>MicroPython</kwd>
        <kwd>Programming the Semantic Web</kwd>
        <kwd>Internet of Things</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>statements in memory, and are a perfect fit for high-performance or resource-limited
applications.</p>
      <p>
        In this demonstration paper, we contribute to the vision of the Semantic Web of Things
by providing a simple and accessible, yet lightweight library for RDF processing, based on
MicroPython. Our library, named urdflib, uses Sord and Serd as the backend, and provides an
API that conforms to the widely used RDFLib Python library [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], in such a way that simple
RDFLib programs could be adapted to constrained devices with a simple change of the module
import declaration:
i m p o r t u r d f l i b a s r d f l i b
      </p>
      <p>In the following sections, we will thoroughly examine the critical components of our research.
Section 2 will extensively cover the design and implementation decisions made for urdflib,
along with an availability statement. Section 3 will provide an initial assessment of the library,
emphasizing its compatibility with Unix and ESP32 ports of MicroPython. Moving on to Section
4, we will investigate other relevant research in this domain and underscore the unique attributes
of urdflib when compared to these works. Lastly, Section 5 will be dedicated to summarizing
our findings, drawing conclusions, and discussing the resulting implications.</p>
    </sec>
    <sec id="sec-2">
      <title>2. Design, Implementation, Availability, Demonstration</title>
      <p>Compatibility with RDFLib. urdflib is intended to provide users with a significant
interpretation of RDFLib, ensuring both ease of use and compatibility with existing code. This
goal was achieved by running tests using the RDFLib repository, thus allowing users to stick to
the RDFLib APIs. However, it is necessary to acknowledge that the underlying implementation
in the urdflib module is written in the C language. As of today, urdflib implements a coherent
subset of the RDFLib API, leaving out namespaces, syntax parsers and serializers, and other
storage and querying plugins.</p>
      <p>Integration with the MicroPython Firmware. Three methods for creating a module in
MicroPython are available: Core module, external module, and port module. The implementation
of urdflib utilizes the Sord, Serd, and Zix C libraries, which required modifications in their code.
As a result, these libraries were merged into a single repository and added to MicroPython as an
external module. Consequently, urdflib now operates as a core module, utilizing Serd and Sord
to establish an API that facilitates RDF manipulation on resource-constrained devices. Two
MicroPython ports have been tested successfully: the Unix and the ESP32 ports.</p>
      <p>Decoupling with the C backend library. The dependency of urdflib to Serd is only
scoped to the separate middleware folder. To migrate to a new RDF C library backend, one
would only need to change the files in this folder.</p>
      <p>Resource availability statement. The source code for urdflib is available from GitHub 3
under the open MIT license. urdflib is registered on Zenodo, with a permanent DOI and canonical
3https://github.com/moh3nhadavi/micropython-urdflib, or https://gitlab.com/coswot/micropython-urdflib
citation.4 Additionally, comprehensive documentation and practical examples illustrating how
to create MicroPython modules like urdflib can be found on GitHub 5.</p>
      <p>Demonstration A demonstration of the library running on an ESP32 via REPL (Read,
Evaluate, Print, Loop), is available online.6</p>
    </sec>
    <sec id="sec-3">
      <title>3. Performance Evaluation</title>
      <p>When the urdflib module is incorporated into MicroPython, it only adds 27 KB to the firmware
size for the ESP32 port, which represents 1˜.5 % of the 1.5 MB original MicroPython firmware
for ESP32. The approximate memory overhead during firmware writing is 2 KB.</p>
      <p>Table 1 summarizes the results of an experiment conducted to assess the process of adding
triples on three diferent platforms, having diferent resource capabilities. The time taken and
memory allocations for operations were measured. The platforms used in the experiment were:
(py-rdflib ) A MacBook Air with RDFLib package installed, a 1,6GHz Dual-Core Intel Core i5
processor, with 16GB 2133 MHz LPDDR3 memory; (mpy-unix-urdflib ) The same MacBook
Air running the MicroPython Unix port with the urdflib module; and ( mpy-esp32-urdflib )
An ESP32 device with a memory capability of 128KB, running MicroPython with the urdflib
module. As illustrated in Table 1, urdflib demonstrates significantly higher speed and lower
memory usage than RDFLib. Step-by-step instructions to compile the code and reproduce the
experiments are available online.7
# triples Initial Time (us)</p>
      <p>Adding Time (us)</p>
      <p>Memory Allocation (B)
4. Related Work
This section lists some related work from the literature on RDF for the IoT (Internet of Things).
RDF4Led [5] is an RDF engine for edge devices. It is compared against Virtuoso and Jena TDB
4https://zenodo.org/record/8342624
5https://github.com/moh3nhadavi/micropython-usermod/tree/update
6https://ci.mines-stetienne.fr/urdflib/demo
7https://github.com/moh3nhadavi/micropython-urdflib-iswc2023
on three types of hardware with 256-512 MB of RAM. The constrained device urdflib targets
are microcontrollers such as the ESP32 with just a few MB of RAM. Cowl [6] is a lightweight
implementation of OWL 2 that aims to target devices with severe processing and memory
limitations. A similar work as ours could be led to use it as the backed for a lightweight version
of a Python implementation of OWL, such as Owlready28. LiRoT [7] use Serd and Sord to
propose a lightweight incremental reasoner that can be embedded in constrained objects, so
that reasoning on them in a fog architecture becomes possible. It demonstrates lower reasoning
time for small numbers of triples, which makes it suitable for the Semantic Web of Things.
Regarding the lightweight RDF syntaxes, [8] proposes to use a CBOR equivalent of JSON-LD as
a lightweight syntax for RDF. RDF/CBOR is another proposed syntax for RDF based on CBOR9.
[9] compares HDT and CBOR for exchanging RDF.</p>
    </sec>
    <sec id="sec-4">
      <title>5. Conclusion and Future Work</title>
      <p>The urdflib module facilitates the development of RDF manipulation programs for embedded
devices that run MicroPython and additionally ensures the API is compatible with the widely
used RDFLib Python library. urdflib may have an impact in contributing to the adoption of
Semantic Web technologies by easing its use for IoT learners and hackers.</p>
      <p>While this library represents a significant advancement in working with RDF on constrained
devices, there are further steps to be taken in the future. These include: (i) use compact data
structure for storing IRIs, (ii) use native datatypes for storing literals instead of their lexical
form, (iii) implement serializers and parsers for compressed syntaxes that minimize memory
usage because most RDF syntaxes are verbose and not suitable for IoT communication scenarios,
and (iv) provide API for lightweight reasoner LiRoT or other features due to the intended goals.</p>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgments References</title>
      <p>This work is supported by grant ANR-19-CE23-0012 from Agence Nationale de la Recherche,
France, for project CoSWoT 10.
8https://pypi.org/project/Owlready2/
9https://openengiadina.codeberg.page/rdf-cbor/
10https://coswot.gitlab.io/</p>
      <p>Champin, M. Watts, U. Holzer, E. Summers, W. Morriss, D. Winston, D. Perttula, F. Kovacevic,
R. Chateauneu, H. Solbrig, B. Cogrel, V. Stuart, Rdflib/rdflib: Rdflib 6.3.2, 2023. URL: https:
//doi.org/10.5281/zenodo.7771749. doi:10.5281/zenodo.7771749.
[5] A. Le-Tuan, C. Hayes, M. Wylot, D. Le-Phuoc, Rdf4led: An rdf engine for lightweight edge
devices, in: Proceedings of the 8th International Conference on the Internet of Things, 2018,
pp. 1–8.
[6] I. Bilenchi, F. Scioscia, M. Ruta, Cowl: A lightweight owl library for the semantic web of
everything, in: International Conference on Web Engineering, Springer, 2022, pp. 100–112.
[7] A. Bento, L. Médini, K. Singh, F. Laforest, Do arduinos dream of eficient reasoners?, in:</p>
      <p>European Semantic Web Conference, Springer, 2022, pp. 289–304.
[8] V. Charpenay, S. Käbisch, H. Kosch, Towards a binary object notation for rdf, in: The
Semantic Web: 15th International Conference, ESWC 2018, Heraklion, Crete, Greece, June
3–7, 2018, Proceedings 15, Springer, 2018, pp. 97–111.
[9] K. Sahlmann, F. Mikolajczak, B. Schnor, Interoperability in the iot–an evaluation of the
semantic-based approach, arXiv preprint arXiv:2203.14585 (2022).</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>D.</given-names>
            <surname>George</surname>
          </string-name>
          , Micropython-python for microcontrollers,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>H.</given-names>
            <surname>Fangohr</surname>
          </string-name>
          ,
          <article-title>A comparison of c, matlab, and python as teaching languages in engineering</article-title>
          , in: Computational Science-ICCS
          <year>2004</year>
          : 4th International Conference, Kraków, Poland, June 6-9,
          <year>2004</year>
          , Proceedings,
          <source>Part IV 4</source>
          , Springer,
          <year>2004</year>
          , pp.
          <fpage>1210</fpage>
          -
          <lpage>1217</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>A.</given-names>
            <surname>Minaburo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Toutain</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Gomez</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Barthel</surname>
          </string-name>
          , J.-C. Zúñiga, Rfc 8724:
          <article-title>Schc: Generic framework for static context header compression</article-title>
          and fragmentation,
          <year>2020</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>D.</given-names>
            <surname>Krech</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. A.</given-names>
            <surname>Grimnes</surname>
          </string-name>
          , G. Higgins,
          <string-name>
            <given-names>J.</given-names>
            <surname>Hees</surname>
          </string-name>
          , I. Aucamp,
          <string-name>
            <given-names>N.</given-names>
            <surname>Lindström</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Arndt</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Sommer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            <surname>Chuc</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Herman</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Nelson</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>McCusker</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Gillespie</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Kluyver</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Ludwig</surname>
          </string-name>
          , P.-A.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>