Skip to content

Instantly share code, notes, and snippets.

@jindrichmynarz
Created November 29, 2013 15:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jindrichmynarz/7707643 to your computer and use it in GitHub Desktop.
Save jindrichmynarz/7707643 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import requests
from requests.auth import HTTPDigestAuth
def crud(graphStoreEndpoint, verb, graph, payload, auth):
function = {
"POST" : requests.post,
"PUT" : requests.put,
"DELETE" : requests.delete,
}[verb]
response = function(
graphStoreEndpoint,
data = payload,
params = {"graph" : graph},
auth = auth
)
return response
def main():
graphStoreEndpoint = "http://localhost:8890/sparql-graph-crud-auth"
username = "dba"
password = "dba"
auth = HTTPDigestAuth(username, password)
namedGraph = "http://example.com"
payload = """
@prefix ex: <http://example.com/> .
ex:A ex:B ex:C .
"""
response = crud(graphStoreEndpoint, "PUT", namedGraph, payload, auth)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment