I would like to retrieve IDs from several databases using InChI as an input, e.g.


One can use unichem from bioservices for this, however, these functions all require the InChIKey as input, e.g.


Is it possible to interconvert the two using bioservices and if not is it possible to somehow use the functions in unichem with InChI rather than the InChIKey?

I tried:

from bioservices import *
u = UniChem()

which works fine, however,


does not work and returns 400.

If it is not passible via bioservices, is there any other python API available for this?


2 Answers 2


Recently I've developed a python lib for converting InChI to InChIKey: https://github.com/liwt31/chembl_ikey. Maybe it will help.

  • $\begingroup$ That's a fork. Could link to the original : github.com/mnowotka/chembl_ikey $\endgroup$
    – gilleain
    Commented Oct 16, 2017 at 13:45
  • $\begingroup$ @gilleain it is indeed a fork. I added python3 support and fixed a bug (InChI without sminor yields wrong InChIKey). $\endgroup$
    – liwt31
    Commented Oct 18, 2017 at 5:03
  • 1
    $\begingroup$ ok, that sounds like a great contribution - but not that you developed it... Sounds like the original author could benefit from a pull request? Just a thought - I'm not the github police! :) $\endgroup$
    – gilleain
    Commented Oct 18, 2017 at 7:50
  • $\begingroup$ ChemDraw's ChemScript is a valuable tool. However, it still runs on Python 3.2. Thank you for this fork - I agree that a pull request would be very beneficial! $\endgroup$
    – tstone-1
    Commented Mar 6, 2021 at 13:50

Not sure if directly possible in bioservices but one can do the following workaround using chemspider:

import requests

host = "http://www.chemspider.com"
getstring = "/InChI.asmx/InChIToInChIKey?inchi="
inchi = 'InChI=1S/C6H14N2O2/c7-4-2-1-3-5(8)6(9)10/h5H,1-4,7-8H2,(H,9,10)/t5-/m0/s1'

r = requests.get('{}{}{}'.format(host, getstring, inchi))
if r.ok:
    res = str(r.text.replace('<?xml version="1.0" encoding="utf-8"?>\r\n<string xmlns="http://www.chemspider.com/">', '').replace('</string>', '').strip())
    print "provide a valid inchi!"

This will give the desired InChIKey


which can be used in unichem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.