Oxford API wrapper
Project description
Oxford.py – A simple wrapper for the Oxford API.
What is this package for?
This package is a wrapper for the Oxford API.
Why? The Oxford API returns large amount of dict
which hard to read, so we decided to simplify it for the users.
(Get your API key and App ID from https://developer.oxforddictionaries.com/)
Usage
The package provides 2 classes, SyncClient
and AsyncClient
.
The methods for the AsyncClient
class are asynchronous and the methods for the SyncClient
class are synchronous, but the same.
If the debug
variable is set to true when creating the SyncClient
or AsyncClient
object, the package will print the parsed api response to the console.
Synchronous Example:
from oxford import SyncClient
client = SyncClient("your_app_id", "your_app_key", language="en-gb")
def main():
definition = client.define("People")[0] # so we get the first definition
print(definition)
main()
Asynchronous Example:
from oxford import AsyncClient
import asyncio
client = AsyncClient("your_app_id", "your_app_key", language="en-gb")
async def main():
definitions = await client.define("People")
definition = definitions[0] # so we get the first definition
print(definition)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Documentation
SyncClient.api_request
This returns the whole massive API response wrapped in a dict
, so if you want to work with this you can.
SyncClient.get_word_definition(word: str)
(or SyncClient.define(word: str)
)
This returns an array with all definitions of the word.
SyncClient.get_word_examples(word: str)
This returns an array with example phrases and/or sentences of the word.
SyncClient.get_audio_file(word: str)
This returns an url to an audio file containing the word's pronunciation.
SyncClient.get_synonyms(word: str)
This returns an array with synonyms of the word.
WordNotFoundException
This exception is thrown if the word is not found in the dictionary (or the server returns a 404). If debug is set to true, the server response will be printed to the console.
HttpException
This exception is thrown if the server returns anything other than 404 or 200 together with a message to help with debugging. If debug is set to true, the server response will be printed to the console.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Oxford.py-Rewrite-1.0.1.tar.gz
.
File metadata
- Download URL: Oxford.py-Rewrite-1.0.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01a382d801d70503acf56c17cbe77d2f5831c2aa8b1bf6d98c89e70ac4401bc8 |
|
MD5 | ac65db024c601d81087bf963a11993f2 |
|
BLAKE2b-256 | 591f6fdeb59beb45a68c3669e68a82b5962d6636723514faa75688048aa33cf7 |
File details
Details for the file Oxford.py_Rewrite-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: Oxford.py_Rewrite-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0fc0e4587da7171e91dcab93d9e02ac6d59150890fb204d5248cd608b8912dc |
|
MD5 | e82c4e12e8659d582be9b0dd55aa2cdb |
|
BLAKE2b-256 | d9d470d295ecabc1199d6322210d4d090da3feaf7d8a3a477264d012d9d02c31 |