Skip to content
Python HYDRA smart client and test console
Branch: master
Clone or download
Latest commit 089640e Mar 25, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
hydra_agent Removed the redis_connection.set from class_objects Mar 10, 2019
.gitignore
.travis.yml Update CI test config Feb 25, 2019
Dockerfile fix docker Dec 8, 2018
LICENSE add LICENSE Jul 8, 2018
README.md Update README.md Mar 25, 2019
docker-compose.yaml Fix docker issue, update requirements, minor bug fixes Jul 26, 2018
redis_setup.sh fix error in if-else statement in redis_setup.sh Feb 10, 2019
requirements.txt Setting Redis version as 2 because of breaking change in Redis 3 Mar 3, 2019
setup.py Update setup.py Mar 12, 2019

README.md

hydra-python-agent Build Status

For a general introduction to Hydra Ecosystem, see hydraecosystem.org.

hydra-python-agent is a smart Hydra client implemented in Python which works with hydrus. Reference implementation is Heracles.ts. Smart clients are generic automated clients that establish resilient connected data networks leveraging knowledge graphs.

General characteristics

The client is designed to:

  • Cache metadata from the Hydra server it connects to, to allow querying on the client-side;
  • Use Redis as a graph-store leveraging redisgraph (see here);
  • simply, metadata and data are loaded from the server and stored in Redis;
  • The graph can be queried using OpenCypher.

The starting objective is to create a querying layer that is able to reach data in one or more Hydra srever/s. Leveraging Redis, clients can construct their own representation of the data stored in one or more Hydra servers; querying the data as they need it, and respond complex semantic queries. This will allow any client connected to any server to have access to an "aggregated view" of the connected network (the network of all the servers it connects to).

Missing bits at the moment

  • For now it is a proof-of-concept, only GET functionality
  • Soon to develop, a reliable synchronization mechanism to allow strong consistency between server-side data and client-side representation (#98).
  • Allow users to interact with the server using Natural Language which is a processed machine consumable language. (under development)

Installation

NOTE: You'll need to use python3.

To install only requirements:

pip3 install -r requirements.txt

or,

To install or setup the client environment, you have to run:

 python3 setup.py install

To install Redis and other Redis modules:

./redis_setup.sh

Quickstart

Demo

To run the demo for hydra-python-agent, you have to follow the instructions:

  • Clone the repo:

      git clone https://github.com/HTTP-APIs/hydra-python-agent.git
    
  • Change directory and switch to the develop branch:

      cd hydra-python-agent
      git checkout -b develop origin/develop
    
  • Now to install the requirements or setup the environment:

    you should follow the instructions of installation.

After setup the environment. You can query or run the client.

  • To run both the things Redis server and the client. You can run the command:

      docker-compose run client
    

    and provide a valid URL and then you can query in querying format.

      `>>>url` #here url should be a valid link, for testing you can use http://35.224.198.158:8080/api
      `>>>help` # it will provide the querying format
    

Code simplification

To create the graph in Redis memory, use(hydra_graph.py) :

    import redis
    from redisgraph import Graph, Node, Edge
    redis_con = redis.Redis(host='localhost', port=6379)
    self.redis_graph = Graph("apidoc", redis_con)

For querying, URL should be provided first:

    url = input("url>>>")
    
    return query(apidoc, url) # apidoc is vocab file provided by url.

The client takes the query as input, like:

    while True:
        print("press exit to quit")
        query = input(">>>")
        if query == "exit":
            break
        elif query == "help":
            help() # provide querying format
        else:
            print(facades.user_query(query))# query can be done with facades class

you can query as following querying formats:

    print("querying format")
    print("Get all endpoints:- show endpoints")
    print("Get all class_endpoints:- show classEndpoints")
    print("Get all collection_endpoints:- show collectionEndpoints")
    print("Get all members of collection_endpoint:-",
          "show <collection_endpoint> members")
    print("Get all properties of objects:-",
          "show objects<endpoint_type> properties")
    print("Get all properties of any member:-",
          "show object<id_of_member> properties ")
    print("Get all classes properties:-show class<class_endpoint> properties")
    print("Get data with compare properties:-",
          "show <key> <value> and/or <key1> <value1>")
    print("Get data by using both opeartions(and,or)",
          " you should use brackets like:-",
          "show model xyz and (name Drone1 or name Drone2)",
          "or, show <key> <value> and (<key> <value> or <key> <value>)")

Query test can be done like this:

    check_data = [['p.id', 'p.operations', 'p.properties', 'p.type'],
                      ['vocab:EntryPoint/Location', 
                       "['POST'", "'PUT'", "'GET']", 
                       "['Location']", 'Location']]
    query = "show classEndpoints"
    self.assertEqual(data,check_data) #data is data retrieve from the Redis.

For more detail take a look at wiki file

References

Hydra-Enabled smart client

Hydra core vocabulary

You can’t perform that action at this time.