Skip to main content

A simple web-scraping based Dictionary Module for Python

Project description

PyDictAPI: Passing GitHub license Release: 1.0.0

PyDictionaryAPI -

A simple web-scraping based Dictionary Module for Python

PyDictAPI is a Dictionary Module for Python 3+ to get a detailed and well-structured meanings of a queried word in JSON format. This module can also be used along with Flask/Django backends to make a full-fledged API server. PyDictAPI searches for the query passed on the web, if the query matches than it returns the definations of that particular query. And incase of incorrect words, the response is returned as a suggestion of the correct word.

Note It uses Dictionary.com for extracting the meanings.

This module uses Requests, BeautifulSoup4 dependencies to scrape the web and find the definations and return it in a well-structured JSON document

Installation

PyDictAPI can be easily installed through PIP

pip install PyDictAPI

Usage

PyDictAPI can be used by creating a MeaningsFinder instance which can take a word as argument

For example,

from PyDictAPI import MeaningsFinder
Meanings = MeaningsFinder()
print(Meanings.findMeanings('apple'))

This is will create a local instance of the MeaningsFinder class and will return a dictionary containing the meanings of the word.
The Response can be seen as:

{
       'word': 'apple', 
       'meanings': [
           {'partOfSpeech': 'noun', 
           'definations': [
                {
                    'definition': 'the usually round, red or yellow, edible fruit of a small tree, Malus sylvestris, of the rose family.', 
                    'example': ''
                }
               ]
               }, 
               {'partOfSpeech': 'noun', 
                'definations': [
                    {
                        'definition': 'a rosaceous tree, Malus sieversii, native to Central Asia but widely cultivated in temperate regions in many varieties, having pink or white fragrant flowers and firm rounded edible fruits', 
                        'example': ''
                    }
                ]
            }
        ]
    }                                                                       

Exceptions

Example - 1: If the word is spelt incorrectly

print(Meanings.findMeanings('helloooo'))

Incase of incorrect words, the response is returned as a suggestion of the correct word
The Response can be seen as:

{
    'message': 'Couldn't find results for helloooo, Did you mean hello?'
}

Example - 2: If the word doesn't exist

print(Meanings.findMeanings('abcdefghijkl'))

The Response can be seen as:

{
    'message': 'Couldn't find any results for ABCDEFGHIJKL, try searching the web again...'
}

About

Current Version: 1.0.0
Copyright (c) 2021 Shawan Mandal.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyDictAPI-1.0.1.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file PyDictAPI-1.0.1.tar.gz.

File metadata

  • Download URL: PyDictAPI-1.0.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.0

File hashes

Hashes for PyDictAPI-1.0.1.tar.gz
Algorithm Hash digest
SHA256 62b075d1c9025505009faf2e94f09139bbe11914c11b43daabb48c96c4e71901
MD5 63e82e2d4de42db82b3e7345627d48ec
BLAKE2b-256 41fea5921d49276c471b0346c830be8d4d80ca9ebfe688307e4195096ceb0cb7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page