Python wrapper for the TLDR text summarization and analysis API.
Project description
tldr-python
Python wrapper for the TLDR text summarization and analysis API available on RapidAPI.
Installation
pip install tldr-python
Introduction - Getting Started
tldr-python is a wrapper over the TLDR text summarization and analysis API. To use this API, create an account on RapidAPI and subscribe to the API.
Once you have a RapidAPI key, initialize a TLDR instance as demonstrated below.
from tldr_python import TLDR
tldr = TLDR('<your RapidAPI key>')
Text Summarization
You can use TLDR to summarize articles on the web with the summarize function. This function accepts either a URL or the raw text of an article on the web.
We can summarize a Wikipedia article about Python using the code below.
summary = tldr.summarize('https://en.wikipedia.org/wiki/Python_(programming_language)', max_sentences=3)
print(summary.text)
The code above produces the following summary:
'[34][35][36][37][38] History[edit] Python was conceived in the late 1980s[39] by Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands as a successor to ABC programming language, which was inspired by SETL,[40] capable of exception handling and interfacing with the Amoeba operating system.[67] The standard library has two modules (itertools and functools) that implement functional tools borrowed from Haskell and Standard ML.[69] Alex Martelli, a Fellow at the Python Software Foundation and Python book author, writes that "To describe something as \'clever\' is not considered a compliment in the Python culture.'
Keyword Extraction
We can also extract keywords from an article as shown below.
keywords = tldr.extract_keywords('https://en.wikipedia.org/wiki/Python_(programming_language)', n_keywords=3)
print(keywords.json)
The result of the code above is a JSON list with the top three scored keywords from the article.
[{'keyword': 'python', 'score': 402}, {'keyword': 'language', 'score': 68}, {'keyword': 'software', 'score': 47}]
Sentiment Analysis
We can also analyze the sentiment of an article with the analyze_sentiment function. This function returns a Sentiment object with sentiment and polarity attributes.
sentiment = tldr.analyze_sentiment('https://en.wikipedia.org/wiki/Python_(programming_language)')
print(sentiment.json)
The code above gives a dictionary with the sentiment and polarity of the article.
{'sentiment': 'positive', 'polarity': 0.10235096701177092}
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
Hashes for tldr_python-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7206e50a6ceba1eefe36e71c3c56fadccedb4306fd4083f02cfe80cc6be87a51 |
|
MD5 | aa6aed21933511246d81fa918a7bd938 |
|
BLAKE2b-256 | 70c60212915e906c45ea41dace4424916b7226fe25ee367379aea93546325b0e |