Retrieve quotes from any Wikiquote article.
Project description
wikiquote
The wikiquote package for Python (>=3.8) allows you to search and retrieve quotes from any Wikiquote article, as well as retrieve the quote of the day.
Installation
You can install the wikiquote package using, for example, pip:
$ pip install --upgrade wikiquote
Usage
>>> import wikiquote
>>> wikiquote.search('The Matrix')
# ['The Matrix (film)', 'The Matrix Revolutions', 'The Matrix Reloaded', 'The Animatrix']
>>> wikiquote.quotes('The Matrix (film)', max_quotes=2) # max_quotes defaults to 20
# ['Don't think you are, know you are.', 'Fate, it seems, is not without a sense of irony.']
>>> wikiquote.quote_of_the_day() # returns a (quote, author) tuple
# 'Always forgive your enemies; nothing annoys them so much.', 'Oscar Wilde'
>>> wikiquote.qotd() # same as quote_of_the_day()
>>> wikiquote.random_titles(max_titles=3) # max_titles defaults to 20
# ['The Lion King', 'Johannes Kepler', 'Rosa Parks']
>>> wikiquote.supported_languages()
# ['de', 'en', 'es', 'eu', 'fr', 'he', 'it', 'pl', 'pt']
Some article titles will lead to a Disambiguation page (like Matrix), which will raise a DisambiguationPageException exception. Usually this happens because there are many articles matching the search term. When this happens, try using search() first, and then use one of the specific article titles found.
If the article searched for does not exist, and no similar results exist, NoSuchPageException will be raised instead.
When requesting the quote of the day, a MissingQOTDException exception will be raised if the quote of the day could not be extracted from Wikiquote's main page. This usually happens because the page's layout has been changed.
Languages
The wikiquote module currently supports the following languages:
| Language | ISO 639-1 Code |
|---|---|
| Basque | eu |
| English | en |
| French | fr |
| German | de |
| Hebrew | he |
| Italian | it |
| Polish | pl |
| Portuguese | pt |
| Spanish | es |
Use the lang parameter to specify the language (defaults to en):
>>> import wikiquote
>>> wikiquote.quotes('Dune', lang='en')[0]
# 'Parting with friends is a sadness. A place is only a place.'
>>> wikiquote.quotes('Victor Hugo', lang='fr')[0]
# 'Le plus lourd fardeau, c'est d'exister sans vivre.'
>>> wikiquote.quotes('Nueve reinas', lang='es')[0]
# 'Más ofendido estás... menos sospechoso parecés.'
>>> wikiquote.quote_of_the_day(lang='es')
# 'He sospechado alguna vez que la única cosa sin misterio es la felicidad, porque se justifica por sí sola.', 'Jorge Luis Borges'
>>> wikiquote.quotes('Hermann Hesse', lang='de')[0]
# 'Nun, aller höhere Humor fängt damit an, daß man die eigene Person nicht mehr ernst nimmt.'
>>> wikiquote.quote_of_the_day(lang='it')
# "Siamo angeli con un'ala sola. Possiamo volare solo restando abbracciati.", 'Luciano De Crescenzo'
>>> wikiquote.quote_of_the_day(lang='pl')
# 'Boże pomóż mi być takim człowiekiem, za jakiego uważa mnie mój pies.', 'Janusz Leon Wiśniewski'
>>> wikiquote.quotes('José Saramago', lang='pt')[0]
# 'Nem a juventude sabe o que pode, nem a velhice pode o que sabe.'
Specifying an invalid language will result in an UnsupportedLanguageException exception.
Tips
Use random.choice() to select a random quote from an article:
>>> import wikiquote, random
>>> random.choice(wikiquote.quotes('Linus Torvalds'))
# 'WE DO NOT BREAK USERSPACE!'
Caveats
In some cases, wikiquote may fail to retrieve quotes from some articles, or the quote of the day (QOTD). This is due to Wikiquote.org's varying internal article layouts: some quotes may be contained in div elements, others in li, etc. depending on the article and the language.
Developing
uv is required to develop wikiquote.
First, make sure you have installed all necessary dependencies, including development dependencies:
$ uv sync
Then, check that all files are correctly formatted, and that the type hints are also correct:
$ uv run make lint
$ uv run make types
After that, check that all tests pass:
$ uv run make test
Some tests may be skipped in the QOTD is not available for some languages.
Finally, create a pull request stating your changes.
Changelog
See the CHANGELOG.md file.
The wikiquote package has been actively maintained for 10+ years 🎉
License
The wikiquote package is licensed under the MIT License.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wikiquote-0.1.18.tar.gz.
File metadata
- Download URL: wikiquote-0.1.18.tar.gz
- Upload date:
- Size: 55.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
685d22d50aae7ffd45b3f9bc32469349138476f5b8de4125ad404dfcb8ba059b
|
|
| MD5 |
b5980137802cd095822ff6f1f40bab5a
|
|
| BLAKE2b-256 |
2338f1fdb0d8d364cbac967bda27544b2cabcd82b8e73aef96a736e4de2b18b4
|
File details
Details for the file wikiquote-0.1.18-py3-none-any.whl.
File metadata
- Download URL: wikiquote-0.1.18-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ed30fe0e0ca34affd2ff942d77a23f9576a8429ea0bd9c458f348a2c4cd29c2
|
|
| MD5 |
e97e5273668fe85be32a96b99ef86516
|
|
| BLAKE2b-256 |
698dd6ac2660d85d1709c38319f1213ea8b8e34ae414691f127b2ceacb48460c
|