Giter VIP home page Giter VIP logo

hydra-py's Introduction

Hydra library for Python

The primary goal is to provide a lib for easily writing Hydra-enabled clients [1].

A secondary goal is to provide a client for Triple Patterns Fragments [2], and an RDFlib [3] Store backed on any TPF service.

Installation

To install this library, from the projet directory, type:

pip install .

NB: developers might want to add the -e option to the command line above, so that modifications to the source are automatically taken into account.

Quick start

To create a Hydra-enabled resource, use:

from hydra import Resource, SCHEMA
res = Resource.from_iri(the_iri_of_the_resource)

If the resource has an API documentation associated with it, it will be available as an attribute. The API documentation provides access to the supported class, their supported properties and operations.

print("Api documentation:")
for supcls in res.api_documentation.supported_classes:
    print("  %s" % supcls.identifier)
    for supop in supcls.supported_operations:
        print("    %s" % supop.identifier)

Alternatively, you can query the resource directly for available operations. For example, the following searches for a suitable operation for creating a new event, and performs it.

create_event = res.find_suitable_operation(SCHEMA.AddAction, SCHEMA.Event)
resp, body = create_event({
    "@context": "http://schema.org/",
    "@type": "http://schema.org/Event",
    "name": "Halloween",
    "description": "This is halloween, this is halloween",
    "startDate": "2015-10-31T00:00:00Z",
    "endDate": "2015-10-31T23:59:59Z",
})
assert resp.status == 201, "%s %s" % (resp.status, resp.reason)
new_event = Resource.from_iri(resp['location'])

And you can go on with the new event you just created...

Triple Pattern Fragments

The hydra.tpf module implements of Triple Pattern Fragments specification [2]. In particular, it provides an implementation of Store, so that TPF services can be used transparently:

import hydra.tpf # ensures that the TPFStore plugin is registered
from rdflib import Graph

g = Graph('TPFStore')
g.open('http://data.linkeddatafragments.org/dbpedia2014')

results = g.query("SELECT DISTINCT ?cls { [ a ?cls ] } LIMIT 10")

Note however that this is experimental at the moment...

References

[1]http://www.hydra-cg.com/
[2](1, 2) http://www.hydra-cg.com/spec/latest/triple-pattern-fragments/
[3]https://rdflib.readthedocs.org/

hydra-py's People

Contributors

pchampin avatar

Watchers

James Cloos avatar  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.