Purpose of this showcase is integrate modern NoSQL backend Redis with FastAPI Python ASGI Framework as API for chemical compounds extended analyze with RDKit Library.
Data set coming from pub chem database, and you can download example from COVID-19 Disease Map here on this link: https://pubchem.ncbi.nlm.nih.gov/#query=covid-19
Pydantic schema was created for PubChem Compounds. You can replace it with your own schema to accept other source of SMILES.
There is many chemical compound sets. Now we are all in days when COVID-19 Pandemic is out there. We all want to know as much as possible about best cure..., and it is my project background. Show power and robustness of Redis with speed of FastAPI and functionality of RDKit to deliver api which allow fast analyze chem molecules.
This showcase can be quickly integrated with other services via REST API and extended to deliver desired chem compound bakery.
Project as whole is build on FastAPI framework, Python 3.11, Redis.
To build, run and test and more... use magic of make.
make help
and you receive below list:
build Build project with compose
clean Reset project containers with compose
down Stop project containers with compose
format Format project code.
help Show this help
lint Lint project code.
lock Refresh pipfile.lock
requirements Refresh requirements.txt from pipfile.lock
safety Check project and dependencies with safety https://github.com/pyupio/safety
test Run project unit tests with coverage
up Run project with compose
-
Download sample JSON from PubChem database i.e. COVID-19 Disease Map here on this link: https://pubchem.ncbi.nlm.nih.gov/#query=covid-19
-
Add SMILES to Redis Hash with
/smiles/add-to-hash
endpointcurl --location --request POST 'http://0.0.0.0:8080/smiles/add-to-hash?redis_hash=covid-19-canonical' \ --header 'Content-Type: application/json' \ --data-binary '@/fastapi-redis/PubChem_compound_text_covid-19_records.json'
and get response like below with
201 Created
{ "number_of_inserted_keys": 2364, "hash_name": "covid-19-canonical" }
-
Compare SMILES code to list loaded in previous step on Redis Hash with
/api/smiles/compare-to-hash
endpointcurl --location --request GET 'http://0.0.0.0:8080/smiles/compare-to-hash?compound=CCC(CC)COC(=O)C(C)NP(=O)(OCC1C(C(C(O1)(C%23N)C2=CC=C3N2N=CN=C3N)O)O)OC4=CC=CC=C4&redis_hash=covid-19-canonical'
and get response like below with
200 OK
{ "number_of_smiles_to_compare": 2364, "similarity": { "CCC(CC)COC(=O)[C@H](C)N[P@](=O)(OC[C@@H]1[C@H]([C@H]([C@](O1)(C#N)C2=CC=C3N2N=CN=C3N)O)O)OC4=CC=CC=C4": 1.0, "CCC(CC)COC(=O)C(C)NP(=O)(OCC1C(C(C(O1)(C#N)C2=CC=C3N2N=CN=C3N)O)O)OC4=CC=CC=C4": 1.0, "C1=C2C(=NC=NN2C(=C1)C3(C(C(C(O3)COP(=O)(O)O)O)O)C#N)N": 0.8964264082374318, "C1=C2C(=NC=NN2C(=C1)[C@]3([C@@H]([C@@H]([C@H](O3)COP(=O)(O)O)O)O)C#N)N": 0.8964264082374318, "C1=C2C(=NC=NN2C(=C1)[C@]3([C@@H]([C@@H]([C@H](O3)CO)O)O)C#N)N": 0.8740109555690809, "C1=C2C(=NC=NN2C(=C1)C3(C(C(C(O3)CO)O)O)C#N)N": 0.8740109555690809 } }
-
For REST API Documentation please use:
http://0.0.0.0:8080/docs
-
Finally, you can use postman collection here Postman Collection
Beside of using latest and greatest version of Redis with it robustness, powerfulness and speed there is FastAPI (modern, fast (high-performance), web framework for building APIs with Python 3.11+ based on standard Python type hints.) already reviewed on thoughtworks and presented in Python Developers Survey 2021 Results as the fifth official annual Python Developers Survey, conducted as a collaborative effort between the Python Software Foundation and JetBrains.
redis-py is already implemented as Python interface to the Redis key-value store.
Special thanks going to maintainers of rdkit-pypi.
Hope you enjoy it.
- 16 APR 2022 aioredis replaced with redis.asyncio
- 15 JUN 2022 re-implement api with redis-om
- 6 APR 2023 bump all project deps and rdkit = "^2022.9.5"
- 6 APR 2023 move project to python 3.11
- 6 APR 2023 switch project to poetry and remove pipenv
- 14 APR 2023 implement rich for logging