Py4dmx - A Python Project to play with DMX's REST API

Writing software is not amongst my professional skills. But as a system administrator I have used bash scripting for many years to solve most of my sysadmin needs. A couple of years ago I started to learn some python also because I was looking for a good way to import data into DMX and play with its REST API.

Just recently I have ported my old py4dmx project from DeepaMehta to the latest DMX version dmx-beta-4-SNAPSHOT. Not everything is working again, but most of it should. If you want to have a look checkout https://git.dmx.systems/dmx-contrib/py4dmx and share your feedback.

1 Like

Hey, this seems to be exactly what I am looking for right now. Can you assist me on how I can setup py4dmx to accomplish the following tasks? That would be really helpful

  1. Perform a log-in (HTTP Basic Authentication request) using my username and password and opening a session
  2. Fetch the topic_id of a custom workspacen given the workspaces URI
  3. Issueing a simple GET (or POST request to my plugins endpoint with an dmx_workspace_id cookie

Is there an example I can get started with or how can configure py4dmx to use my credentials and fetch the correct workspace?

I hope my request reaches you being well and I would be very thankful for your support.

Hi mukil,

to my understanding the script can perform everything you were asking for. If not, I am happy to extend it to your needs.

  1. There are three ways to define your identity. For now the script only supports http. Let me know if you need SSL support. I will add this with priority then.
  • Using the command line: dmx.py -l -u “myusername” -p “mypassword” …
  • Using the config-file dmx.cfg in the script directory (default)
  • Using DMX’s config.property file by providing the path: dmy.py -c /path/to/config.properties
  1. Let me know if you actually need this. You can add the workspace’s type URI to each POST request with -w. (see 3.) and define a default workspace to use in the config file.

  2. The script sets the dmx_workspace_id cookie and uses it.

Here are some examples. Please let me know if you miss something.

  • dmx.py --help
    shows the list of options.

  • dmx.py -s
    reads server setting and credentials from config file dmx.cfg to login and to return the current session id.

  • dmx.py -C -u "myusername" -p "mypassword"
    creates a new user with user name “myusername” and password “mypassword”.

  • dmx.py -s -l -u "myusername" -p "mypassword"
    will login user “myusername” into DMX and output the current session id.

  • dmx.py -c /etc/dmx/config.properties -s
    uses the config file /etc/dmx/config.properties to read server settings and admin password from there to login to server and output the current session id.

  • dmx.py -l -u "myusername" -p "mypassword" -m -w "my shared workspace" -n "pied.piper"
    adds the user with username “pied.piper” to my workspace named “my shared workspace”.

  • dmx.py -f note_example.json -w "DMX"
    creates a new note topic from file note_example.json in workspace “DMX”.

  • dmx.py -N "foo" -B "bar" -w "Private Workspace"
    creates a new note topic with title “foo” and body “bar” in workspace “Private Workspace”.

  • dmx.py -M "my topicmap" -w "Private Workspace"
    creates a new topicmap “my topicmap” in workspace “Private Workspace”.

  • dmy.py -R -i 1234 -o 5678 -x 150 -y 150 -P True -w "Private Workspace"
    reveales a topic with id 1234 on topicmap with id 4567 at position x=150 and y=150 in pinned mode.

In the meantime I added SSL support. :wink: So now you can access e.g. https://demo.dmx.systems to test the script. Do not forget to copy dmx.cfg.example to dmx.cfg and adjust it to your needs.

You can also test the brand new feature to set the remote URL via command line:

dmx.py -l -u "myusername" -p "mypassword" -U https://dmx.example.com -s
will login user “myusername” into DMX instance at URL https://dmx.example.com and output the current session id.

Thank you, @jpn, for your time and providing this great help. Now I have a good overview of that CLI and that should help get us going quite fast.

Thanks for your work!