Divan Hafez Poems & Omen
This library gives you access to the Hafez Poems. To get more information about this poet, you can check https://en.wikipedia.org/wiki/Hafez.
Poems can be accessed as following:
- By the number of poem,
- By searching a query,
- Random poem (known as Omen or
Falin Persian)
Installation
This package can be installed:
- using
pip:
pip install hafez
- using
Makefileon a cloned/forked repo:
make install
- using
pipon a cloned/forked repo:
pip install -e . --upgrade --upgrade-strategy only-if-needed
Methods
hafez.total_poems()->int
It returns `int`, the total number of poems available in the package.
hafez.get_poem(poem_id: int)->dict
It returns the poem in a dictionary format (see Poem Data Structure)
-
poem_id: int: It is a number between1andhafez.total_poems(). -
hafez.omen()orhafez.fal()->dict
It returns a random poem in a dictionary format (see Poem Data Structure)
hafez.search(qeury: str, exact_match: bool = False)->list
It returns a list of poems in a dictionary format (see Poem Data Structure)
-
query: str: It is a string to search within the verses of the Divan Hafez -
`exact_match: bool': if True, it will search for exact match of the query
-
hafez.download_all_audio(force: boolean = False)->int
It downloads all the audio files.
-
force: boolean = False: If it is set toFalse, it only downloads the file if not previously downloaded. If set toTrue, it will force to re-download and replace the existing file. -
hafez.download_audio(poem: int)->int
It downloads the audio file of the given `poem`. It returns `1`, once the downloaded is completed.
hafez.get_audio(poem: int=1, download: boolean = True)->str
It returns the absolute path of the audio file related to the given `poem`.
poem: int=1: It is the poem number.download: boolean = True: Ifdownload=True, it downloads the audio file if not existing.
Poem's Data Structure
{"id": 1,
"poem": [],
"interpretation": "",
"alt_interpretation": "",
"mp3": "https://..."}
Example
# it returns the total number of poems
# returns: int
total_number_of_poems = hafez.total_poems()
# get a poem by ID
# returns: dict
poem_5 = hafez.get_poem(5)
# get a random poem - omen (fal)
# returns: dict
omen = hafez.omen() # same as: hafez.fal()
# search within the verses of poems
# returns: list[dict]
search_result = hafez.search("حافظ")
Database
The poems of Divan Hafez are extracted from an open-source database as below:
Source: https://github.com/mahmoud-eskandari/HafezFaalDatabase
Vocal Audios
The vocal audio files are done by Ms. Modares Zadeh, and it is available below:
Source: https://avayemastan.deklame.net/hafez/
Demo
You can access the demo version deployed on Streamlit server at:
https://divan-hafez.streamlit.app/
Developer(s)
Kaveh Bakhtiyari - Website | Medium | LinkedIn | GitHub
Contribution
Feel free to join the open-source community and contribute to this repository.
Metadata
Release files for hafez 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hafez-0.4.2.tar.gz | 314.5 kB | Without provenance | Details for hafez-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hafez-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for hafez-0.4.2-py3-none-any.whl |
Total release size: 655.8 kB
Release files / hafez-0.4.2.tar.gz
| Download URL | hafez-0.4.2.tar.gz |
|---|---|
| Size | 314.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b8f86e76a501deec10e7ee918ef99b87da5af774819ccdb0a30c767a0926f5f6
|
|
BLAKE2b-256 checksum How to use checksums |
23e110e42218a3eee3bd4f78941500b96bf65bb37ba02c918e9ba96722367eab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / hafez-0.4.2-py3-none-any.whl
| Download URL | hafez-0.4.2-py3-none-any.whl |
|---|---|
| Size | 341.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0b2f82fbdbbdff29564b1a1962d5e4138c0c1004791f259412b8c68af848306c
|
|
BLAKE2b-256 checksum How to use checksums |
70c40730eddb60adcf8358548d1ed9d826651d83d0573e2efdaefd8384509827
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for hafez 0.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.