datamuse 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
datamuse/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ from .datamuse import Datamuse
2
+
3
+ __all__ = [
4
+ "Datamuse",
5
+ ]
@@ -0,0 +1,40 @@
1
+ from types import MappingProxyType
2
+ from typing import Literal, LiteralString, TypeAlias
3
+
4
+ Word: TypeAlias = LiteralString
5
+
6
+
7
+ RelatedWordCode = Literal[
8
+ "nouns_adjective",
9
+ "adjectives_noun",
10
+ "synonyms",
11
+ "triggers",
12
+ "antonyms",
13
+ "hypernyms",
14
+ "hyponyms",
15
+ "holonyms",
16
+ "meronyms",
17
+ "frequent_followers",
18
+ "frequent_predecessors",
19
+ "homophones",
20
+ "consonant",
21
+ ]
22
+
23
+
24
+ _lookup_related_code = MappingProxyType(
25
+ {
26
+ "nouns_adjective": "jja",
27
+ "adjectives_noun": "jjb",
28
+ "synonyms": "syn",
29
+ "triggers": "trg",
30
+ "antonyms": "ant",
31
+ "hypernyms": "spc",
32
+ "hyponyms": "gen",
33
+ "holonyms": "com",
34
+ "meronyms": "par",
35
+ "frequent_followers": "bga",
36
+ "frequent_predecessors": "bgb",
37
+ "homophones": "hom",
38
+ "consonant": "cns",
39
+ }
40
+ )
datamuse/datamuse.py ADDED
@@ -0,0 +1,99 @@
1
+ import functools
2
+ from typing import final
3
+
4
+ import certifi
5
+ import urllib3
6
+
7
+ from datamuse.annotations import RelatedWordCode, Word, _lookup_related_code
8
+
9
+
10
+ @final
11
+ class Datamuse:
12
+ """
13
+ The [Datamuse](https://www.datamuse.com/) [API](https://www.datamuse.com/api/) is a word-finding query engine for developers.
14
+
15
+ You can use it in your apps to find words that match a given set of constraints and that are likely in a given context.
16
+ You can specify a wide variety of constraints on meaning, spelling, sound, and vocabulary in your queries, in any combination.
17
+ """
18
+
19
+ __API_URL = "api.datamuse.com"
20
+ __slots__ = ("__pool",)
21
+
22
+ def __init__(self) -> None:
23
+ self.__pool = urllib3.HTTPSConnectionPool(
24
+ host=self.__API_URL,
25
+ port=443,
26
+ cert_reqs="CERT_REQUIRED",
27
+ ca_certs=certifi.where(),
28
+ )
29
+
30
+ @functools.lru_cache
31
+ def __get_words(self, **kwds: Word | RelatedWordCode) -> list[Word]:
32
+ response = self.__pool.request(method="GET", url="/words", fields=kwds)
33
+ return [word["word"] for word in response.json()]
34
+
35
+ @functools.lru_cache
36
+ def __get_suggestions(self, **kwds: Word | RelatedWordCode) -> list[Word]:
37
+ response = self.__pool.request(method="GET", url="/sug", fields=kwds)
38
+ return [word["word"] for word in response.json()]
39
+
40
+ def synonyms(self, ml: Word):
41
+ """
42
+ words with a meaning similar to `ml`
43
+
44
+ :param ml: means like
45
+ """
46
+ return self.__get_words(ml=ml)
47
+
48
+ def associations(self, ml: Word, start: Word = "*", end: Word = "*"):
49
+ """
50
+ words related to `ml`
51
+
52
+ :param ml: means like
53
+ :param start: start with
54
+ :param end: end in
55
+ """
56
+ return self.__get_words(ml=ml, sp=start + end)
57
+
58
+ def homophones(self, sl: Word):
59
+ """
60
+ words that sound like `sl`
61
+
62
+ :param sl: sounds like
63
+ """
64
+ return self.__get_words(sl=sl)
65
+
66
+ def pattern(self, start: Word, end: Word, letters: int):
67
+ """
68
+ words that start with `start`, end in `end`, and have `letters` in between
69
+
70
+ :param start: start with
71
+ :param end: end in
72
+ :param letters: letters in between
73
+ """
74
+ return self.__get_words(sp=f"{start[0]}{'?' * letters}{end[0]}")
75
+
76
+ def orthographic_neighbours(self, sp: Word):
77
+ """
78
+ words that are spelled similarly to `sp`
79
+
80
+ :param sp: spelled like
81
+ """
82
+ return self.__get_words(sp=sp)
83
+
84
+ def related(self, word: Word, rel: RelatedWordCode):
85
+ """
86
+ words that are related by `rel`
87
+
88
+ :param word: the word
89
+ :param rel: related word
90
+ """
91
+ return self.__get_words(**{f"rel_{_lookup_related_code[rel]}": word})
92
+
93
+ def suggestions(self, s: Word):
94
+ """
95
+ sugesstions from prefix hint string `s`
96
+
97
+ :param s: prefix hint string
98
+ """
99
+ return self.__get_suggestions(s=s)
@@ -0,0 +1,34 @@
1
+ Metadata-Version: 2.4
2
+ Name: datamuse
3
+ Version: 0.1.0
4
+ Summary: datamuse is a simple wrapper around the datamuse api https://www.datamuse.com/api/
5
+ Author-email: Bivas Kumar <thetrotfreak@yahoo.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://pypi.org/project/datamuse
8
+ Project-URL: Source, https://github.com/thetrotfreak/datamuse
9
+ Project-URL: Documentation, https://thetrotfreak.github.io/datamuse
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.11
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: certifi>=2026.1.4
16
+ Requires-Dist: urllib3>=2.6.3
17
+ Dynamic: license-file
18
+
19
+ # datamuse
20
+
21
+ `datamuse` is a simple wrapper around the [datamuse](https://www.datamuse.com/) [api](https://www.datamuse.com/api/)
22
+
23
+ ## Installing
24
+
25
+ You can install `datamuse` via `pip` / `pypi`:
26
+
27
+ ```shell
28
+ pip install datamuse
29
+ ```
30
+
31
+ ## Acknowledgements
32
+
33
+ - [Harvey Beeferman, 1942–2024](https://beeferman.org/harvey/)
34
+ - [datamuse](https://www.datamuse.com/)
@@ -0,0 +1,8 @@
1
+ datamuse/__init__.py,sha256=3iBEY2GhRlufmsa_jbPcL5pNmFxlcmVBnPDrb2viXF0,62
2
+ datamuse/annotations.py,sha256=sH2B4EQsTMLCFrGJ4b90UFME3TdezOVqRfTdEyXIPlI,850
3
+ datamuse/datamuse.py,sha256=cSH0UIESr7UP_X2w6dyo6TfFXoSveiXJ-MyDUuVvmbc,2957
4
+ datamuse-0.1.0.dist-info/licenses/LICENSE,sha256=QOL-I0yJ7jgs2oNQFHl_Q5oYfQ9dbcXxE9lQC3o8hhs,1068
5
+ datamuse-0.1.0.dist-info/METADATA,sha256=-KIThoI4BefAbVP-fkxzfZLfp4VNNoDExXB8-UPrKig,1027
6
+ datamuse-0.1.0.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
7
+ datamuse-0.1.0.dist-info/top_level.txt,sha256=WPSt0EOXULT7kkMOZin9HFm1RNBYgoLM0q7rTxcDH_w,9
8
+ datamuse-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bivas Kumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ datamuse