Grid Server : Focus on Python remote run

GridServer is a bus. But it include some advanced capabilities beyon pure sub/unsub classical bus feature, such as microserver deployement, or KeyValue in memory embeded database and…

Python Instant execution feature !

Better code chunk than long story 😉

Show me the code

Here is a delphi (Pascal object) exemple :

Connection :

lconnectResp := lCli.Connect('admin','admin',TGRIDProtocolFormat.Binary); 
 if lConnectResp.Status then
  begin
    Writeln('Connected to GRID admin protocol - Welcome');
    Writeln('Protocol '+lcli.Protocol.ProtocolNameSlashFormat);

You can do many things, such as get server informations :

            lInfoResp := lCli.Infos;
            if lCli.LastStatus then
            begin
              Writeln('GRIDServerName             : '+lInfoResp.GRIDServerName+' '+lInfoResp.GRIDArch+' ('+lInfoResp.GRIDCompiler+')');
              Writeln('ServerGenuineName         -> '+lInfoResp.ServerGenuineName);
              Writeln('ServerHostCPUArchitecture -> '+lInfoResp.ServerHostCPUArchitecture);
              Writeln('ServerHostArchitecture    ->'+lInfoResp.ServerHostArchitecture);
              Writeln('ServerHostOS              ->'+lInfoResp.ServerHostOS);
              Writeln('ServerHostOSBuild         ->'+lInfoResp.ServerHostOSBuild);
            end

But keep focus on python !

Get current Python version Server side :

lCli.instantPythonVersion;
This snapshot is taken from “GRIDClientConsole” binary, which is basicaly just a demo app to access to GRID Server’s services.

And now, run a python code !


lCli.instantPythonRun('def gridmain():'+sLineBreak+' print("hello world".upper())')
delphi “hello world” to “HELLO WORLD” – the most expensive uppercase ever !

Pretty simple ! You will note that the python code is a bit special, because it define a method (python’s function) “gridmain()”. I’ll talk about that later, it is as is for instance to be conforme to “multithread” execution of the stuff. You can execute legacy normal code too.

For sure, that’s work on all other platforme, (c#, python itself, cpp) since GRID Server main protocole can handle json or binary format on the same port. (pure cpp binary protocol is in test, open source delivery soon ;))

the very nice part, is that this execution take inside python env : All the libs you previously installed on your python env will be available (such as PIL, numPi, or whatever) in this interface !

so, the very all power of python is available via GRID Server, on your app (here delphi), without embedded heavy library !

Installation

Ok, just before that, you have juste to enable grid server to run Python :

To do that you must have a python installed (2.x or 3.x as you want, or even many different installation : Grid know how to manage that, and it can manage multi python version.

Now, GS Part : go to the Grid Server command line (on another instance for exemple) and fellow this step :

  • admin mode, by typing “admin” under GS console
the Admin menu in all it’s glory ;/
  • Select python management (2)
    • Enter python version MAJOR.MINOR
    • Enter API Version (not relevant for instance) – enter whatever you want.
    • Enter the name of the lib (without path)
    • Enter the path of the lib (without file name)
  • Select (1) to view the current selection
  • And finaly, select 4 to define default python version for InstantPython feature
  • In our case (above), we put “1” when system asks for “define Default ID”.

Here it is ! Python is now ready to be invoke trought GRID Server’s KissB API. Enjoy !

  • See you soon on the Grid Server GitHub !
  • Remember that you have precompiled binaries here.
  • Linux (x86) and Arm version (with python support !) is comming soon.

GRID Server Open Sourced

The latest version of GRID Server comes with a great news : This software is now open source.

Written in full FPC/Delphi, all code available and presented under MPL 2.0.

If you are interested in this server and its capabilities:

  • MQTT Broker
  • KissB protocol (Bus protocol, like MQTT, but simpler and extended to wider use)
  • Key Value in memory DB
  • Python Proxy

do not hesitate to try it, and if you want to go further, we can deliver it in various forms : native Win service, Nix Daemon, components, customs, licence customization and so on : Do not hesitate to contact us !

Soon here, we’ll have the opportunity to talk more about, through its capabilities !