pydsfapi - Official Python Client Library for DSF [beta]



  • pydsfapi

    Here is a first version of the official Python 3.5+ client library to DuetSoftwareFramework.

    I covers all connections modes available with the C# client. Currently the Machine Model is implemented as a very simple class that holds all the values as dictionaries. This might change in the future once the object model is stable.

    You can find it at GitHub.

    Feedback

    Please test it and report any issues you find here so it can be fixed/changed to get to a stable API as soon as possible.

    Request to Python experts

    This code has been ported with a less-than-optimal Python knowledge. 😉 I would kindly ask for Python experts to have a look where things can be made more Pythonic or implementations can be improved (I assume significant improvements can be done with the custom HTTP endpoint code in regards of starting and stopping the EventLoop).



  • Great!! I'll start looking at it this afternoon from both a functional and Python perspective.



  • Fantastic! This was somewhere "on my list" and I'd much rather use an existing.

    Great community here...

    May I request a couple of usage examples in one of the readme.md files? I'd like to convert my tool alignment scripts ASAP.



  • @Danal said in pydsfapi - Official Python Client Library for DSF [beta]:

    Fantastic! This was somewhere "on my list" and I'd much rather use an existing.

    Actually your existing library was a jump-start for me. 😄

    Great community here...

    So thanks to you as well!

    May I request a couple of usage examples in one of the readme.md files? I'd like to convert my tool alignment scripts ASAP.

    I will add some. EDIT: This might take until tomorrow. 😉

    EDIT2: Just so you don't have to starve until then

    # Initialize a new CommandConnection with debug mode enabled
    command_connection = connections.CommandConnection(debug=True)
    # Connect to default socket location
    command_connection.connect()
    
    try:
    	# Run a command
    	command_connection.perform_simple_code("M117 I'm alive", CodeChannel.SPI)
    finally:
    	# Close the connection
    	command_connection.close()
    


  • If @chrishamm doesn't show up soon, I think I'm just going to rewrite the entire DSF in python (or nodejs). 🙂



  • @gtj0 said in pydsfapi - Official Python Client Library for DSF [beta]:

    If @chrishamm doesn't show up soon, I think I'm just going to rewrite the entire DSF in python (or nodejs). 🙂

    I would actually vote for NodeJS, but either would be OK.



  • P.S. I did fix the M999 bug. Caveat Emptor and all that, this is my very first .net on Linux... etc, etc. If anyone is willing to try the 1.2.4.0 version of DuetControlServer with this fix, download this file:

    http://danalspub.com/wp-content/uploads/2020/03/DuetControlServer.zip

    Unzip, and place the two files inside in /opt/dsf/bin

    The 'DuetControlServer' file should have attributes of -rwxr-xr-x. If for some reason it does not, run chmod 755 DuetControlServer

    After the copies:
    sudo systemctl stop duetcontrolserver
    sudo systemctl start duetcontrolserver

    If you decide to go back, run:

    sudo apt-get reinstall duetcontrolserver

    or

    sudo apt-get reinstall duetcontrolserver=specific version number you wish

    You can find all available versions via:
    apt-cache policy duetcontrolserver



  • @gtj0 said in pydsfapi - Official Python Client Library for DSF [beta]:

    If @chrishamm doesn't show up soon, I think I'm just going to rewrite the entire DSF in python (or nodejs). 🙂

    He's currently working on both DWC and DSF to get the ObjectModel up to date.

    But either way please don't replace one interpreted language for another. On a RPi use something that runs natively. Use Go or Rust. 😂



  • @wilriker said in pydsfapi - Official Python Client Library for DSF [beta]:

    @gtj0 said in pydsfapi - Official Python Client Library for DSF [beta]:

    If @chrishamm doesn't show up soon, I think I'm just going to rewrite the entire DSF in python (or nodejs). 🙂

    He's currently working on both DWC and DSF to get the ObjectModel up to date.

    But either way please don't replace one interpreted language for another. On a RPi use something that runs natively. Use Go or Rust. 😂

    HA!. I hear COBOL is making a comeback. 🙂 Actually the new "thing" is nim



  • @Danal (and interested others):

    I have pushed a change that has added an examples.py that shows minimal examples of the three (four) most common usage scenarios.

    Also mind that I renamed the main entry point from a generic connections.py to a more specific pydsfapi.py.



  • Thank you! I will take a look, and target adapting this into my tool alignment scrips.


Log in to reply