Name | redditwarp JSON |
Version |
1.3.0
JSON |
| download |
home_page | None |
Summary | A library for interacting with the Reddit API. |
upload_time | 2024-07-01 07:09:55 |
maintainer | None |
docs_url | None |
author | Pyprohly |
requires_python | <4.0,>=3.8 |
license | MIT |
keywords |
reddit
api
wrapper
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# RedditWarp
[![Latest version](https://img.shields.io/pypi/v/redditwarp)](https://pypi.org/p/redditwarp/)
![Supported Python versions](https://img.shields.io/pypi/pyversions/redditwarp)
[![Discord guild](https://img.shields.io/discord/1084793643673600062?logo=discord&logoColor=white&logoWidth=20&label=&labelColor=5865F2&color=7289DA)](http://pyprohly.github.io/redditwarp/discord-invite)
A comprehensive, type-complete, easy-to-learn Python Reddit API wrapper.
RedditWarp is a Python library that simplifies working with the Reddit API.
It handles the complexities of the Reddit API in a way that is comprehensive,
highly discoverable, and static-type conscious. It includes a variety of useful
tools to facilitate a wide range of use cases, and even provides tools for
accessing the API in ways previously not possible.
Look how easy it is to use:
```python
import redditwarp.SYNC
client = redditwarp.SYNC.Client()
it = client.p.front.pull.hot(5)
l = list(it)
for subm in l:
print("r/{0.subreddit.name} | {0.id36}+ ^{0.score} | {0.title!r:.80}".format(subm))
```
## Features
* A consistent and easy-to-use programming interface.
* Modern type-complete codebase.
* Sync and asynchronous IO support.
* Automatic rate limit handling.
* A comprehensive and discoverable index of API procedures.
* Model classes that are fully typed and sensibly wrap API structures.
* Formal data structures to facilitate comment tree traversals and pagination.
* HTTP transport library agnosticism.
* OAuth2 tooling and CLI utilities to help manage auth tokens.
* A simple event-based listing endpoint streaming framework.
## Installation
**Requires Python 3.8+.**
Type annotations may use 3.9 features.
Code examples will assume 3.10.
Install/update:
pip install -U redditwarp
## Demonstration
<details open>
<summary>Examples</summary>
```python
import redditwarp.SYNC
client = redditwarp.SYNC.Client()
# Display the first 5 submissions on the Reddit frontpage.
it = client.p.front.pull.hot(5)
l = list(it)
for subm in l:
print("r/{0.subreddit.name} | {0.id36}+ ^{0.score} | {0.title!r:.80}".format(subm))
# How many subscribers does r/Python have?
subr = client.p.subreddit.fetch_by_name('Python')
print(subr.subscriber_count)
# Display the top submission of the week in the r/YouShouldKnow subreddit.
m = next(client.p.subreddit.pull.top('YouShouldKnow', amount=1, time='week'))
print(f'''\
{m.permalink}
{m.id36}+ ^{m.score} | {m.title}
Submitted {m.created_at.astimezone().ctime()}{' *' if m.is_edited else ''} \
by u/{m.author_display_name} to r/{m.subreddit.name}
''')
# Get the first comment of a submission.
tree_node = client.p.comment_tree.fetch('uc8i1g', sort='top', limit=1)
c = tree_node.children[0].value
print(f'''\
{c.submission.id36}+{c.id36} ^{c.score}
u/{c.author_display_name} says:
{c.body}
''')
# List the moderators of r/redditdev.
it1 = client.p.moderation.pull_users.moderators('redditdev')
for mod in it1:
print(mod.name)
```
</details>
<details>
<summary>More examples</summary>
```python
# ...
# Need credentials for these next few API calls.
CLIENT_ID = '...'
CLIENT_SECRET = '...'
REFRESH_TOKEN = '...'
client1 = redditwarp.SYNC.Client(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN)
# Who am I?
me = client1.p.account.fetch()
print(f"Hello u/{me.name}!")
# Show my last 5 comments.
it2 = client.p.user.pull.comments(me.name, 5)
for comm in it2:
print('###')
print(comm.body)
# Show my last 10 saved items.
from redditwarp.models.submission_SYNC import Submission
from redditwarp.models.comment_SYNC import Comment
it3 = client1.p.user.pull.saved(me.name, 10)
l = list(it3)
for obj in l:
print('###')
match obj:
case Submission() as m:
print(f'''\
{m.permalink}
{m.id36}+ ^{m.score} | {m.title}
Submitted {m.created_at.astimezone().ctime()}{' *' if m.is_edited else ''} \
by u/{m.author_display_name} to r/{m.subreddit.name}
''')
case Comment() as c:
print(f'''\
{c.permalink}
{c.submission.id36}+{c.id36} ^{c.score}
u/{c.author_display_name} says:
{c.body}
''')
# Submit a link post to r/test.
client1.p.submission.create.link('test',
"Check out this cool website", "https://www.reddit.com")
# Reply to a submission.
from redditwarp.util.extract_id_from_url import extract_submission_id36_from_url
id36 = extract_submission_id36_from_url("https://www.reddit.com/comments/5e1az9")
comm1 = client1.p.submission.reply(id36, "Pretty cool stuff!")
# Delete the comment reply.
client1.p.comment.delete(comm1.idn)
```
</details>
<details>
<summary>Streaming example</summary>
```python
#!/usr/bin/env python
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from redditwarp.models.submission_ASYNC import Submission
import asyncio
import redditwarp.ASYNC
from redditwarp.streaming.makers.subreddit_ASYNC import create_submission_stream
from redditwarp.streaming.ASYNC import flow
async def main() -> None:
client = redditwarp.ASYNC.Client()
async with client:
submission_stream = create_submission_stream(client, 'AskReddit')
@submission_stream.output.attach
async def _(subm: Submission) -> None:
print(subm.id36, '~', subm.title)
@submission_stream.error.attach
async def _(exc: Exception) -> None:
print('ERROR:', repr(exc))
await flow(submission_stream)
asyncio.run(main())
```
</details>
## Support
Post any questions you have to [r/redditdev].
[r/redditdev]: https://www.reddit.com/r/redditdev/
Join the conversation in the RedditWarp [Discord guild].
[Discord guild]: http://pyprohly.github.io/redditwarp/discord-invite
## Links
* [Repository](https://github.com/Pyprohly/redditwarp)
* [PyPI](https://pypi.org/p/redditwarp/)
* [Documentation](https://redditwarp.readthedocs.io/)
* [r/redditdev]
* [Discord guild]
Raw data
{
"_id": null,
"home_page": null,
"name": "redditwarp",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "reddit, api, wrapper",
"author": "Pyprohly",
"author_email": "pyprohly@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/03/f8/48d632fa5d21f805d0298dbdf70e6c802c9f5df048b5fe10074dd279ac47/redditwarp-1.3.0.tar.gz",
"platform": null,
"description": "\n# RedditWarp\n\n[![Latest version](https://img.shields.io/pypi/v/redditwarp)](https://pypi.org/p/redditwarp/)\n![Supported Python versions](https://img.shields.io/pypi/pyversions/redditwarp)\n[![Discord guild](https://img.shields.io/discord/1084793643673600062?logo=discord&logoColor=white&logoWidth=20&label=&labelColor=5865F2&color=7289DA)](http://pyprohly.github.io/redditwarp/discord-invite)\n\nA comprehensive, type-complete, easy-to-learn Python Reddit API wrapper.\n\nRedditWarp is a Python library that simplifies working with the Reddit API.\nIt handles the complexities of the Reddit API in a way that is comprehensive,\nhighly discoverable, and static-type conscious. It includes a variety of useful\ntools to facilitate a wide range of use cases, and even provides tools for\naccessing the API in ways previously not possible.\n\nLook how easy it is to use:\n\n```python\nimport redditwarp.SYNC\n\nclient = redditwarp.SYNC.Client()\n\nit = client.p.front.pull.hot(5)\nl = list(it)\nfor subm in l:\n print(\"r/{0.subreddit.name} | {0.id36}+ ^{0.score} | {0.title!r:.80}\".format(subm))\n```\n\n## Features\n\n* A consistent and easy-to-use programming interface.\n* Modern type-complete codebase.\n* Sync and asynchronous IO support.\n* Automatic rate limit handling.\n* A comprehensive and discoverable index of API procedures.\n* Model classes that are fully typed and sensibly wrap API structures.\n* Formal data structures to facilitate comment tree traversals and pagination.\n* HTTP transport library agnosticism.\n* OAuth2 tooling and CLI utilities to help manage auth tokens.\n* A simple event-based listing endpoint streaming framework.\n\n## Installation\n\n**Requires Python 3.8+.**\nType annotations may use 3.9 features.\nCode examples will assume 3.10.\n\nInstall/update:\n\n pip install -U redditwarp\n\n## Demonstration\n\n<details open>\n <summary>Examples</summary>\n\n```python\nimport redditwarp.SYNC\n\nclient = redditwarp.SYNC.Client()\n\n# Display the first 5 submissions on the Reddit frontpage.\nit = client.p.front.pull.hot(5)\nl = list(it)\nfor subm in l:\n print(\"r/{0.subreddit.name} | {0.id36}+ ^{0.score} | {0.title!r:.80}\".format(subm))\n\n# How many subscribers does r/Python have?\nsubr = client.p.subreddit.fetch_by_name('Python')\nprint(subr.subscriber_count)\n\n# Display the top submission of the week in the r/YouShouldKnow subreddit.\nm = next(client.p.subreddit.pull.top('YouShouldKnow', amount=1, time='week'))\nprint(f'''\\\n{m.permalink}\n{m.id36}+ ^{m.score} | {m.title}\nSubmitted {m.created_at.astimezone().ctime()}{' *' if m.is_edited else ''} \\\nby u/{m.author_display_name} to r/{m.subreddit.name}\n''')\n\n# Get the first comment of a submission.\ntree_node = client.p.comment_tree.fetch('uc8i1g', sort='top', limit=1)\nc = tree_node.children[0].value\nprint(f'''\\\n{c.submission.id36}+{c.id36} ^{c.score}\nu/{c.author_display_name} says:\n{c.body}\n''')\n\n# List the moderators of r/redditdev.\nit1 = client.p.moderation.pull_users.moderators('redditdev')\nfor mod in it1:\n print(mod.name)\n```\n\n</details>\n\n<details>\n <summary>More examples</summary>\n\n```python\n# ...\n\n# Need credentials for these next few API calls.\nCLIENT_ID = '...'\nCLIENT_SECRET = '...'\nREFRESH_TOKEN = '...'\nclient1 = redditwarp.SYNC.Client(CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN)\n\n# Who am I?\nme = client1.p.account.fetch()\nprint(f\"Hello u/{me.name}!\")\n\n# Show my last 5 comments.\nit2 = client.p.user.pull.comments(me.name, 5)\nfor comm in it2:\n print('###')\n print(comm.body)\n\n# Show my last 10 saved items.\nfrom redditwarp.models.submission_SYNC import Submission\nfrom redditwarp.models.comment_SYNC import Comment\nit3 = client1.p.user.pull.saved(me.name, 10)\nl = list(it3)\nfor obj in l:\n print('###')\n match obj:\n case Submission() as m:\n print(f'''\\\n{m.permalink}\n{m.id36}+ ^{m.score} | {m.title}\nSubmitted {m.created_at.astimezone().ctime()}{' *' if m.is_edited else ''} \\\nby u/{m.author_display_name} to r/{m.subreddit.name}\n''')\n case Comment() as c:\n print(f'''\\\n{c.permalink}\n{c.submission.id36}+{c.id36} ^{c.score}\nu/{c.author_display_name} says:\n{c.body}\n''')\n\n# Submit a link post to r/test.\nclient1.p.submission.create.link('test',\n \"Check out this cool website\", \"https://www.reddit.com\")\n\n# Reply to a submission.\nfrom redditwarp.util.extract_id_from_url import extract_submission_id36_from_url\nid36 = extract_submission_id36_from_url(\"https://www.reddit.com/comments/5e1az9\")\ncomm1 = client1.p.submission.reply(id36, \"Pretty cool stuff!\")\n\n# Delete the comment reply.\nclient1.p.comment.delete(comm1.idn)\n```\n\n</details>\n\n<details>\n <summary>Streaming example</summary>\n\n```python\n#!/usr/bin/env python\nfrom __future__ import annotations\nfrom typing import TYPE_CHECKING\nif TYPE_CHECKING:\n from redditwarp.models.submission_ASYNC import Submission\n\nimport asyncio\n\nimport redditwarp.ASYNC\nfrom redditwarp.streaming.makers.subreddit_ASYNC import create_submission_stream\nfrom redditwarp.streaming.ASYNC import flow\n\nasync def main() -> None:\n client = redditwarp.ASYNC.Client()\n async with client:\n submission_stream = create_submission_stream(client, 'AskReddit')\n\n @submission_stream.output.attach\n async def _(subm: Submission) -> None:\n print(subm.id36, '~', subm.title)\n\n @submission_stream.error.attach\n async def _(exc: Exception) -> None:\n print('ERROR:', repr(exc))\n\n await flow(submission_stream)\n\nasyncio.run(main())\n```\n\n</details>\n\n## Support\n\nPost any questions you have to [r/redditdev].\n\n[r/redditdev]: https://www.reddit.com/r/redditdev/\n\nJoin the conversation in the RedditWarp [Discord guild].\n\n[Discord guild]: http://pyprohly.github.io/redditwarp/discord-invite\n\n## Links\n\n* [Repository](https://github.com/Pyprohly/redditwarp)\n* [PyPI](https://pypi.org/p/redditwarp/)\n* [Documentation](https://redditwarp.readthedocs.io/)\n* [r/redditdev]\n* [Discord guild]\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library for interacting with the Reddit API.",
"version": "1.3.0",
"project_urls": null,
"split_keywords": [
"reddit",
" api",
" wrapper"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0bc4a62b72c184e2d98bd0a16a4fa7d693e82cb40ae2342c74d8e7acb66eebc5",
"md5": "c8d8bdbf9601f9f0b1b359c285c80199",
"sha256": "752139e961965524e534295ddef363316ffcfafc9abb6e8a1cb08cc90645db97"
},
"downloads": -1,
"filename": "redditwarp-1.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c8d8bdbf9601f9f0b1b359c285c80199",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 483990,
"upload_time": "2024-07-01T07:09:53",
"upload_time_iso_8601": "2024-07-01T07:09:53.935413Z",
"url": "https://files.pythonhosted.org/packages/0b/c4/a62b72c184e2d98bd0a16a4fa7d693e82cb40ae2342c74d8e7acb66eebc5/redditwarp-1.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "03f848d632fa5d21f805d0298dbdf70e6c802c9f5df048b5fe10074dd279ac47",
"md5": "4230e38a6b532df6693de39e64d7938e",
"sha256": "962a092ae0e8e40f703af40996a6b7d896b718893e4c619d16740aa2426c7901"
},
"downloads": -1,
"filename": "redditwarp-1.3.0.tar.gz",
"has_sig": false,
"md5_digest": "4230e38a6b532df6693de39e64d7938e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 207632,
"upload_time": "2024-07-01T07:09:55",
"upload_time_iso_8601": "2024-07-01T07:09:55.839657Z",
"url": "https://files.pythonhosted.org/packages/03/f8/48d632fa5d21f805d0298dbdf70e6c802c9f5df048b5fe10074dd279ac47/redditwarp-1.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-01 07:09:55",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "redditwarp"
}