hydraplatform / hydra-client-python Goto Github PK
View Code? Open in Web Editor NEWHydra Platform client libraries for Python
Home Page: http://hydraplatform.org
License: MIT License
Hydra Platform client libraries for Python
Home Page: http://hydraplatform.org
License: MIT License
The RemoteJSONConnection example does not seem to work. I have tried both the version from pip and using the latest version (updated yesterday). Trying this:
import hydra_client as hc
hb_conn = hc.RemoteJSONConnection(url='http://localhost:8080/json')
hb_conn.login(username='root', password='')
gives me this:
Traceback (most recent call last):
File "base.py", line 19, in
hb_conn.login(username='root', password='')
File "C:\Users\honeywillrs\AppData\Local\Continuum\anaconda3\lib\site-packages\hydra_client\connection\remote_json_connection.py", line 112, in login
resp = self.call('login', login_params)
File "C:\Users\honeywillrs\AppData\Local\Continuum\anaconda3\lib\site-packages\hydra_client\connection\remote_json_connection.py", line 93, in call
raise RequestError(err)
hydra_client.exception.RequestError: {'message': "Client.AuthenticationError:Invalid authentication request for HydraError({'message': b'root', 'code': '0000'})", 'code': '200'}>
This was using Windows 10 and installed hydraserver via pip.
I suggest revising the library to accept arguments as kwargs, instead of a dictionary of arguments. For example, instead of conn.add_network({'net': network})
, one would call conn.add_network(net=network)
.
Here's my catchall code for a generic call to the hydra-server:
def call(self, fn, **kwargs):
# convert any boolean parameters to 'Y' or 'N'.
for kwarg in kwargs.keys():
if type(kwargs[kwarg]) == bool:
kwargs[kwarg] = 'Y' if kwargs[kwarg] is True else 'N'
return self._call(fn, kwargs)
I use this as conn.call('add_network', net=network)
. This could be modified to accommodate specific functions of course:
def add_network(self, **kwargs):
return self.call('add_network', **kwargs)
The installation readme states to install like so:
pip install hydra-client
This is a completely unrelated package. The instructions should say:
pip install hydra-client-python
Probably using a click
.
Some example commands.
hydra-cli network delete 5
hydra-cli project add "My Awesome Project"
hydra-cli project rename "My Awesome Project" "My Very Awesome Project"
hydra-cli user list
Based on some discussion on app behaviour, it would be desireable to have a situation where we can simplify the 'main' code of an app which currently looks like (pseudocode):
def main():
try:
some_setup() #Parse arguments
run_app_code() #Run The model / export the data, whatever
some_teardown() #Write Logs, delete data, whatever
message = 'Finished Successfully'
except HydraError:
message = 'Some known error has occurred'
except Exception
message = 'Some unknown error has occurred'
create_xml_response('MyApp', network_id, [scenario_id],, message=message)
Could we get rid of the need to do this in every app, and let the client library handle it for us? This would also incorporate the ability to specify in the app whether you should raise the exception or write the xml response to stdout.
When an app do a login, if there is an error (username/password missing or incorrect) the login method raise an exception.
This is correct when there is the need to manage it at an higher level, but it is bad when the app is executed from the command line, because it is hard to understand that the problem was just a wrong login instead of something worse.
every app will have an additional switch "suppress_exception" so that in case of errors they will be showed with a friendly message (eg. "The username is mandatory" or "login info wrong") and the exception will not be shown.
Code suggestion to add in the app:
if self.suppress_exception:
log.error("Unable to log in")
else:
Raise("Unable to log in")
I was having an issue (with MySQL) whereby commits were not happening as expected. For example, using hydra_client.call('add_project', new_project)
would return the correct project, with a new ID, but the project wasn't committed to the DB.
I narrowed down the issue to self.autocommit
in the hydra_client.JSONConnection somehow being corrupted. Whereas it defaults to True, it changes from True to some function (<function BaseConnection.getattr..wrapped at 0x00000187FB68A6A8>), so that if self.autocommit == True
now becomes False, and no commits are made.
I'm not sure what the root cause is, but my band-aid fix seems to work: just set hc.autocommit = True
before every call. I alread have hydra_client in my own custom wrapper class, so it's one line, but still this is an issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.