Construct and Python - Part 1

This post will show how to connect to a Construct Data Port and submit RDF data.

If an instance of Construct is available, this code will insert two pieces of RDF in N3 format. The first of these is good RDF, the second of these is not. The script is below, and example output beneath that again.

  1. #Import the python construct proxy.
  2. from construct.proxy import proxy
  3. from construct.constructservice import ServiceError
  4. #Create a new Proxy object.
  5. proxy = proxy()
  6. print “Executing Script”
  7. try:
  8. # Send a VALID piece of RDF to the data store
  9. insertGoodResponse = proxy.insert(“<http://hello><http://construct>\”world\”.”);
  10. print “Response to good RDF: “ + str(insertGoodResponse)
  11. # response should be “1″
  12. # Send an INVALID piece of RDF to the data store.
  13. insertBadResponse = proxy.insert(“<http://badly><http://formed>\”rd\”f\”.”);
  14. print “Response to bad RDF: “ + str(insertBadResponse)
  15. # response should be “None”
  16. except ServiceError, e:
  17. print e.value
  18. # Close the proxy.
  19. proxy.close()

If this code has executed correctly (i.e., if an instance of Construct is discovered) the following will be printed:

Executing Script

Response to good RDF: 1

Response to bad RDF: None

If the Construct proxy is not found the following will be printed:

Executing Script

Error - unable to contact an instance node of Construct (using address localhost:3826). Is the Construct Proxy running at that address?

and if no instance of Construct is discovered the following will be printed:

Executing Script

Error: No instance of Construct found. Please ensure you are within Zeroconf range of a running instance of Construct
This post is the first part of a tutorial on construct and python. Part 2 of this tutorial is here and part 3 is here

0 Responses to “Construct and Python - Part 1”


  1. No Comments
  1. 1 Construct and Python - Part 2 at Construct
  2. 2 Construct and Python - Part 3 at Construct

Leave a Reply