We’ve joined forces with Smartlogic to reveal smarter decisions—together.

Two Languages Shockingly Easy to Use With MarkLogic

As a MarkLogic consultant, my job is as often about managing MarkLogic or moving data in and out of MarkLogic as it is about the application with which the end-user interacts.  Here are two languages that don’t have large, formal MarkLogic toolkits like the DMSDK or Java Client API, but are easy to “plug in” to MarkLogic.  It’s possible to use these languages to build tools or scripts to simplify your MarkLogic work.

Why is it easy? MarkLogic is built to be standards compliant, interacting primarily over two REST APIs: a management API and a client API. Because these are standard REST APIs that can return JSON or XML responses, any language that can support REST will work with MarkLogic.  In 2017 that’s a pretty low bar, so almost every language is covered.

That said, some languages have particularly good support for
XML and HTTP (including digest authentication for projects that don’t use basic authentication). Here are two of them, and my experience integrating each with MarkLogic in particular, and RESTful management and data access in general.

Using Go With MarkLogic

The Go language – sometimes called golang – is a language introduced by Google in 2007.  I enjoy it because Go is a language I can pretty much keep in my head all at once, kind of like when I first learned C.  It’s low level and about as fast as C.  Unlike C, Go has garbage collection, reflection, and built-in concurrency.  There is a rich tooling community around Go.  Where Go really shines is in the container space, where Go is to containers what C is to Unix.

To use Go with MarkLogic there’s only one dependency, and that’s only if you’re using the Digest authentication method.  I also created my own version to which I’ve added header support.  The code is fairly simple, for example, let’s get a list of all the hosts in a cluster:

package main

import (

    digest "github.com/paul-hoehne/go-http-digest-auth-client"

func main() {
    req := digest.NewRequest("admin", "kat", "GET", "", "")
    resp, _ := req.Execute()
    io.Copy(os.Stdout, resp.Body)

What makes Go attractive is that go programs can be run on the command line (using the “go run” command) or statically compiled into binaries with no runtime requirements. The binaries are easily cross-compiled to other architectures, supporting Windows, Linux x64, Linux ARM, and MacOS with little effort. Because Go has no runtime, is statically compiled, and relatively fast, it may become the language of choice for containers that include nothing but a minimal Linux userland.

Using Python With MarkLogic

Python is another language that integrates well with MarkLogic’s JSON API support.  The only dependency needed is the requests package.

Of course, MarkLogic plugs nicely into Python.  As an example, there is the MarkLogic Python management API.

import requests
from requests import auth

me = auth.HTTPDigestAuth("admin", "kat")
resp = requests.get("", auth=me)

Four lines of code!

Because the “json” method on the response from the requests package returns a Python dictionary, the data is immediately usable. Python is available for every computer architecture from a Raspberry Pi to a z/OS mainframe.  Because Python is everywhere, has an incredibly rich eco-system, is very approachable to even programming novices, is included with Linux, supported in Visual Studio for Windows, and is interpreted, it is a great choice for system administration and data movement tasks.

Another thing that makes Python so attractive is that it’s extremely popular in statistics and data science.  Libraries like SciPi, Pandas, Numpy, and Keras make machine learning with Python approachable to a wide number of people.  In the data science community, the Jupyter notebook tool based on Python is becoming ubiquitous.  In addition to data science and machine learning, Python has libraries for almost everything. As an interpreted language, there is no compile phase or management of executables separate from source code.

Other Languages That Work With MarkLogic

Java, Node, cURL, Ruby, C++ … The list of language and tools usable with MarkLogic is essentially limitless.  While Java and Node have specialized, idiomatic APIs into MarkLogic, those MarkLogic-supplied libraries actually call the same REST API that Go, Python, or other languages would use.  Plugging MarkLogic directly into your latest Python data science project or Rails application may be simpler, quicker, and easier than you think.

Start a discussion

Connect with the community




Most Recent

View All

Unifying Data, Metadata, and Meaning

We're all drowning in data. Keeping up with our data - and our understanding of it - requires using tools in new ways to unify data, metadata, and meaning.
Read Article

How to Achieve Data Agility

Successfully responding to changes in the business landscape requires data agility. Learn what visionary organizations have done, and how you can start your journey.
Read Article

Scaling Memory in MarkLogic Server

This not-too-technical article covers a number of questions about MarkLogic Server and its use of memory. Learn more about how MarkLogic uses memory, why you might need more memory, when you need more memory, and how you can add more memory.
Read Article
This website uses cookies.

By continuing to use this website you are giving consent to cookies being used in accordance with the MarkLogic Privacy Statement.