{"id":16005835,"url":"https://github.com/laundmo/prawvents","last_synced_at":"2025-03-17T19:32:17.641Z","repository":{"id":57454560,"uuid":"325162973","full_name":"laundmo/prawvents","owner":"laundmo","description":"A Small wrapper for PRAW that allows for Event-based bots","archived":false,"fork":false,"pushed_at":"2020-12-29T02:59:22.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T07:34:45.279Z","etag":null,"topics":["api-wrapper","praw","reddit","reddit-api"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/prawvents/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laundmo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"ko_fi":"laundmo"}},"created_at":"2020-12-29T02:10:28.000Z","updated_at":"2023-03-31T19:13:27.000Z","dependencies_parsed_at":"2022-09-04T19:10:33.603Z","dependency_job_id":null,"html_url":"https://github.com/laundmo/prawvents","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laundmo%2Fprawvents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laundmo%2Fprawvents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laundmo%2Fprawvents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laundmo%2Fprawvents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laundmo","download_url":"https://codeload.github.com/laundmo/prawvents/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243878478,"owners_count":20362433,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-wrapper","praw","reddit","reddit-api"],"created_at":"2024-10-08T11:22:02.064Z","updated_at":"2025-03-17T19:32:17.365Z","avatar_url":"https://github.com/laundmo.png","language":"Python","funding_links":["https://ko-fi.com/laundmo"],"categories":[],"sub_categories":[],"readme":"\u003ca name=\"prawvents\"\u003e\u003c/a\u003e\n# PRAWvents, Events for PRAW\nA simple wrapper to write event-based bots with [PRAW](https://praw.readthedocs.io/en/latest).\n\n## Scope\nYou can register event handlers for everything thats based on the praw [stream_generator](https://praw.readthedocs.io/en/latest/code_overview/other/util.html#praw.models.util.stream_generator)\nAny other functionality is offered as-is, since this subclasses the main PRAW [Reddit](https://praw.readthedocs.io/en/latest/code_overview/reddit_instance.html) instance.\n\nA async version of this should be possible, but is not yet planned.\n\n# Quickstart\n\nThis is a simple bot that will print out the subreddit and the submission title for all posts in the subreddits AskReddit and pics, while skipping the existing posts in AskReddit.\nThis example assumes the presence of a [praw.ini](https://praw.readthedocs.io/en/latest/getting_started/configuration/prawini.html) in your working directory.\n```py\nfrom prawvents import EventReddit\nfrom praw import reddit\n\nr = EventReddit(user_agent=f\"ExampleBot for prawvents version (0.0.1) by /u/laundmo\") # change the description and username!\n\nsub1 = r.subreddit(\"AskReddit\")\nsub2 = r.subreddit(\"pics\")\n\ndef handle_exception(e): # very dumb exception handler\n    print(e)\n\n@r.register_event(sub1.stream.submissions, err_handler=handle_exception, skip_existing=True)\n@r.register_event(sub2.stream.submissions, err_handler=handle_exception)\ndef handle(submission: reddit.Submission):\n    print(submission.subreddit, submission.title)\n\nr.run_loop()\n```\n\n# Docs\n\u003ca name=\"prawvents.RedditEventDecorator\"\u003e\u003c/a\u003e\n## RedditEventDecorator Objects\n\n```python\nclass RedditEventDecorator()\n```\n\nDecorator class for event handlers.\n\n\u003ca name=\"prawvents.RedditEventDecorator.__init__\"\u003e\u003c/a\u003e\n#### \\_\\_init\\_\\_\n\n```python\n | __init__(reddit: praw.Reddit, stream: RStream, err_handler: Callable)\n```\n\nInitialise RedditEventDecorator.\n\n**Arguments**:\n\n- `reddit` _EventReddit_ - The `EventReddit` instance\n- `stream` _RStream_ - The stream to which the event responds.\n- `err_handler` _Callable_ - A function thats called with the exception as a argument.\n\n\u003ca name=\"prawvents.RedditEventDecorator.__call__\"\u003e\u003c/a\u003e\n#### \\_\\_call\\_\\_\n\n```python\n | __call__(f: Callable) -\u003e Callable\n```\n\nSet the event handler.\n\n**Arguments**:\n\n- `f` _Callable_ - The event handler function.\n\n\n**Returns**:\n\n- `Callable` - The function.\n\n\u003ca name=\"prawvents.EventReddit\"\u003e\u003c/a\u003e\n## EventReddit Objects\n\n```python\nclass EventReddit(praw.Reddit)\n```\n\nMain Reddit instance, subclass of [praw.Reddit](https://praw.readthedocs.io/en/latest/code_overview/reddit_instance.html).\n\n**Arguments**:\n\n- `praw` _praw.Reddit_ - Praw Reddit superclass.\n\n\u003ca name=\"prawvents.EventReddit.__init__\"\u003e\u003c/a\u003e\n#### \\_\\_init\\_\\_\n\n```python\n | __init__(*args, **kwargs)\n```\n\nInitialise EventReddit. All arguments are passed through to [praw.Reddit](https://praw.readthedocs.io/en/latest/code_overview/reddit_instance.html)\n\n\u003ca name=\"prawvents.EventReddit.register_event\"\u003e\u003c/a\u003e\n#### register\\_event\n\n```python\n | register_event(stream: RStream, err_handler: Callable = None, **kwargs) -\u003e RedditEventDecorator\n```\n\nRegister a event, should generally be used as a decorator like this:\n\n```py\n@r.register_event(subreddit.stream.submissions, err_handler=handle_exception)\ndef event_handler(submission):\n    pass\n```\n\n**Arguments**:\n\n- `stream` _RStream_ - The stream to which the event responds.\n- `err_handler` _Callable, optional_ - The error handler for this event. Defaults to None.\n\n\n**Returns**:\n\n- `RedditEventDecorator` - The decorator instance.\n\n\u003ca name=\"prawvents.EventReddit.handle_exception\"\u003e\u003c/a\u003e\n#### handle\\_exception\n\n```python\n | handle_exception(f: Callable, e: Exception)\n```\n\nHandle a Exception happening in a function f\n\n**Arguments**:\n\n- `f` _Callable_ - The function which threw the exception.\n- `e` _Exception_ - The exception which was thrown.\n\n\n**Raises**:\n\n- `e` - The Exception that was thrown.\n\n\u003ca name=\"prawvents.EventReddit.run_stream_till_none\"\u003e\u003c/a\u003e\n#### run\\_stream\\_till\\_none\n\n```python\n | run_stream_till_none(stream: RStream, funcs: Iterable[Callable]) -\u003e None\n```\n\nRuns a stream until none is returned\n\n**Arguments**:\n\n- `stream` _RStream_ - The finalized stream to run.\n- `funcs` _Iterable[Callable]_ - The functions which handle this stream.\n\n\u003ca name=\"prawvents.EventReddit.run_loop\"\u003e\u003c/a\u003e\n#### run\\_loop\n\n```python\n | run_loop(interweave=True) -\u003e None\n```\n\nRun the event loop. If interweave is Truthy, events from multiple streams will be mixed to ensure a single high-traffic stream cant take up the entire event loop. This is highly \nrecommended.\n\n**Arguments**:\n\n- `interweave` _bool, optional_ - Whether to interweave streams to ensure fair distribution. Defaults to True.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaundmo%2Fprawvents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaundmo%2Fprawvents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaundmo%2Fprawvents/lists"}