Git Product home page Git Product logo

hydra-python-agent's Introduction

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.

Quick Start

Our Hydra Agent has different interfaces that you can try:

General characteristics

The Agent is designed to:

  • Provide a seamless Client that can be used to communicate with Hydra APIs
  • Cache metadata from the Hydra server it connects to, to allow querying on the client-side
  • Maintain a syncrhonization mechanism which makes sure cached resources are consistent
  • The graph can be queried using OpenCypher.

The final goal is to create a Client that can connected to multiple hydrus servers and operate between them while caching information in a graph-based database(Redis). This should enable the client to have an "aggregated view" of the connected network (the network of all the servers it connects to) and make complex sematic queries to it.

Installation

NOTE: You'll need to use python3. Using venv(virtual environment) is recommended.

Clone and setup a virtual environment:

git clone https://github.com/HTTP-APIs/hydra-python-agent.git
cd hydra-python-agent
python3 -m venv venv
source venv/bin/activate

Install dependencies and setup Agent:

pip3 install --upgrade pip
pip3 install -r requirements.txt
python3 setup.py install

Setup Redis which is used as caching layer(if permission denied use sudo):

./redis_setup.sh

Setup hydrus Since this is an API Client, we need an appropriate Hydra Server to query to. To setup a localhost follow the instructions at https://github.com/HTTP-APIs/hydrus#demo. You might want to run hydrus serve --no-auth to skip setting up headers.

Agent package

After installing the Agent and running Redis, as per instructions above, you can do something like:

from hydra_agent.agent import Agent 

agent = Agent("http://localhost:8080/serverapi/") # <- hydrus Server URL 
agent.get("http://localhost:8080/serverapi/DroneCollection/")

The agent supports GET, PUT, POST or DELETE:

  • GET - used to READ resources or collections
  • PUT - used to CREATE new resources in the Server
  • POST - used to UPDATE resources in the Server
  • DELETE - used to DELETE resources in the Server

To GET a existing resource you should:

agent.get("http://localhost:8080/serverapi/<CollectionType>/<Resource-ID>")
agent.get("http://localhost:8080/serverapi/<CollectionType>/")

To PUT a new resource you should:

new_resource = {"@type": "Drone", "name": "Drone 1", "model": "Model S", ...}
agent.put("http://localhost:8080/serverapi/<CollectionType>/", new_resource)

To UPDATE a resource you should:

existing_resource["name"] = "Updated Name"
agent.post("http://localhost:8080/serverapi/<CollectionType>/<Resource-ID>", existing_resource)

To DELETE a resource you should:

agent.delete("http://localhost:8080/serverapi/<CollectionType>/<Resource-ID>")

More than that, Agent extends Session from https://2.python-requests.org/en/master/api/#request-sessions, so all methods like auth, cookies, headers and so on can also be used.

Natural-language-like Command Line Tool

If you've followed the installation instructions you can run:

python hydra_agent/querying_mechanism.py

Another alternative to run the CLT is using docker componse. To run both Redis server and the client(stop any Redis instance before), you can run the command:

    docker-compose run client

To query you should provide a hydrus URL first:

     url>>> http://localhost:8080/serverapi/ 
   

Obs.: If failing to connect to localhost running the Agent via Docker, head to issue #104.

  • Natural Language querying format

Run help inside the CLT to get the querying format.

    >>>help # it will provide the querying format

You can query the server with the following format:

Get all endpoints:- show endpoints Get all class_endpoints:- show classEndpoints Get all collection_endpoints:- show collectionEndpoints Get all members of collection_endpoint:- show < collection_endpoint > members Get all properties of objects:- show objects< endpoint_type > properties Get all properties of any member:- **show object< id_of_member > properties ** Get all classes properties:- show class< class_endpoint > properties Get data with compare properties:- show < key > < value > and/or < key1 > < value1 > 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 >)

For more detail take a look at wiki file

Missing bits at the moment

  • For the Web GUI there's a list of future enhacements here.
  • For now the Natural language CLT it is a proof-of-concept, only GET functionality

References

Hydra-Enabled smart client

Hydra core vocabulary

hydra-python-agent's People

Contributors

guttz avatar sandeepsajan0 avatar xadahiya avatar mec-is avatar shravandoda avatar pchampin avatar de-sh avatar prajwalm2212 avatar chrizandr avatar krritik avatar vcode11 avatar

Watchers

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