I'm writing a Python script to do some work on my backups from TheBrain.

I've noticed that Thought Notes that contain links to other thoughts use values in the URL that can't directly be found anywhere else in the backup, so my current assumption is that these are hashed / encoded values of some kind.

How does TheBrain generate these values? I need to be able to decipher these back to the Thought Id value so I can honor these links in my output.
If you have a long GUID string (like d6a0dd87-5892-5bb9-b097-bf44ef5464b0) you can convert it to and from these short URLs with code like this (unsupported, left as an exercise to the reader; this is C# code):

public static string ToShortGuid(this Guid newGuid) {
string modifiedBase64 = Convert.ToBase64String(newGuid.ToByteArray())
.Replace('+', '-').Replace('/', '_') // avoid invalid URL characters
.Substring(0, 22);
return modifiedBase64;

public static Guid ParseShortGuid(this string shortGuid) {
string base64 = shortGuid.Replace('-', '+').Replace('_', '/') + "==";
Byte[] bytes = Convert.FromBase64String(base64);
return new Guid(bytes);
Jared Updike
TheBrain Technologies
Engineering Team
Strange. I feel like I'm close -- when converting from the GUID to what you call the ShortGuid, using Python, I can get part of the string to match, but not all of it.
Ah, ok, solved. Difference in the way C# and Python natively order the elements in a GUID/UUID.
Any chance you would share your Python code?  I am working on a QGIS Plugin to map all Thoughts with a Google Map URL and it would be great to provide a link back to TheBrain Thought.

I figured it out :-)

If you are interested, check out wikipedia for a comparison of the guid and uuid formats.

I'll post my python code later today.

Here is my python code for creating TheBrain short URL's.


    def construct_short_url(self, brain_id, thought_id, thought_name):

        thought_brainid_guid = uuid.UUID(self.reorder_guid(brain_id))

        thought_brainid_b64 = base64.b64encode(thought_brainid_guid.bytes).decode("utf-8")

        thought_brainid_b64 = thought_brainid_b64.replace('+', '-').replace('/', '_')

        thought_brainid_b64 = thought_brainid_b64[0:22]


        thought_id_guid = uuid.UUID(self.reorder_guid(thought_id))

        thought_id_b64 = base64.b64encode(thought_id_guid.bytes).decode("utf-8")

        thought_id_b64 = thought_id_b64.replace('+', '-').replace('/', '_')

        thought_id_b64 = thought_id_b64[0:22]


        thought_short_url = "brain://api.thebrain.com/" + \

                            thought_brainid_b64 + "/" + \

                            thought_id_b64 + "/" + \

                            thought_name.replace(" ", "").replace("(", "").replace(")", "")


        return thought_short_url


    def reorder_guid(self, guid):

        guid_02 = guid[0:2]

        guid_24 = guid[2:4]

        guid_46 = guid[4:6]

        guid_68 = guid[6:8]

        guid_911 = guid[9:11]

        guid_1113 = guid[11:13]

        guid_1416 = guid[14:16]

        guid_1618 = guid[16:18]

        guid_split = guid[18:]

        guid_reordered = guid_68 + guid_46 + guid_24 + guid_02 + "-" \

                          + guid_1113 + guid_911 + "-" \

                          + guid_1618 + guid_1416 \

                          + guid_split

        return guid_reordered


Newsletter Signup  Newsletter        Visit TheBrain Blog   Blog       Follow us on Twitter   Twitter       Like Us on Facebook   Facebook         Circle Us on Google+  Google         Watch Us on Youtube  YouTube       

TheBrain Mind Map & Mindmapping Software     Download TheBrain Mind Mapping Software