Skip to content

Showcase of Redis integration with Python FastAPI framework as API backend for RDKit: Open-Source Cheminformatics Software

License

Notifications You must be signed in to change notification settings

thanhtn208/fastapi-redis

 
 

Repository files navigation

fastapi-redis

developer language license visitors

fastapi-redis

Project Description

Purpose of this showcase project is integrate modern NoSQL backend Redis with Async Python 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 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 quick analyze chem molecules.

For puprose of Redis 2021 Hack-a-toon I added only two cases to load chem molecules to redis cache and to compare all molecules which we already have with new one.

This can be really quickly integrate with other services via REST API and extended to deliver desired chem compound bakery.

Project as whole is build on python asyncio including REST, Redis connection and transactions and unit tests.

How to Setup

To build , run and test and more ... use magic of make help to play with this project.

make help

and you receive below list:

black                Apply black in project code
build                Build project with compose
clean                Reset project containers with compose
down                 Stop project containers with compose
flake8               Flake8 checks on project code
help                 Show this help
isort                Sort imports in project code
lock                 Refresh pipfile.lock
mypy                 Run mypy checks on project code
requirements         Refresh requirements.txt from pipfile.lock
test-cov             Run project unit tests with coverage
up                   Run project with compose

How to Play

  1. Download sample JSON form PubChem database i.e. COVID-19 Disease Map here on this link: https://pubchem.ncbi.nlm.nih.gov/#query=covid-19

  2. Add SMILES to Redis Hash with /api/smiles/add-to-hash endpoint

    curl --location --request POST 'http://0.0.0.0:8080/api/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"
    }
  3. Compare SMILES code to list loaded in previous step on Redis Hash with /api/smiles/compare-to-hash endpoint

    curl --location --request GET 
    'http://0.0.0.0:8080/api/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
        }
    }
  4. For REST API Documentation please use: http://0.0.0.0:8080/docs

Backbone

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.6+ based on standard Python type hints.) already reviewed on thoughtworks

Hope you enjoy it.

About

Showcase of Redis integration with Python FastAPI framework as API backend for RDKit: Open-Source Cheminformatics Software

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Python 85.7%
  • Makefile 8.0%
  • Dockerfile 5.1%
  • Shell 1.2%