{"id":17823084,"url":"https://github.com/artofcode-/stackl","last_synced_at":"2025-07-25T23:41:33.072Z","repository":{"id":57470995,"uuid":"154909739","full_name":"ArtOfCode-/stackl","owner":"ArtOfCode-","description":"Python library for connecting to Stack Exchange chat","archived":false,"fork":false,"pushed_at":"2018-10-28T13:19:14.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T16:16:47.140Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ArtOfCode-.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-27T00:54:08.000Z","updated_at":"2021-08-26T11:24:15.000Z","dependencies_parsed_at":"2022-09-10T02:02:25.544Z","dependency_job_id":null,"html_url":"https://github.com/ArtOfCode-/stackl","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtOfCode-%2Fstackl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtOfCode-%2Fstackl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtOfCode-%2Fstackl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtOfCode-%2Fstackl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArtOfCode-","download_url":"https://codeload.github.com/ArtOfCode-/stackl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246796459,"owners_count":20835391,"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":[],"created_at":"2024-10-27T17:50:55.449Z","updated_at":"2025-04-02T10:29:40.501Z","avatar_url":"https://github.com/ArtOfCode-.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stackl\nPython library for connecting to Stack Exchange chat.\n\n## Installation\nIt's on PyPI.\n\n    pip3 install stackl\n\nStackl is targeted to support Python 3, and built against Python 3.6. It almost certainly doesn't support Python 2,\nthough I haven't actually tested it, and may break on lower versions of Python 3. Support requests/bug reports will only\nbe accepted for versions at or over Python 3.5.\n\n## Usage/Examples\nThe basic premise: import, create a chat client, and use that to send/receive messages.\n\n```python\nimport stackl\n\n\nclient = stackl.ChatClient()\n\n# Log in to just chat.stackexchange.com and chat.stackoverflow.com; ignore chat.meta.stackexchange.com.\nclient.login('me@example.com', 'secure-password123', servers=['stackexchange.com', 'stackoverflow.com'])\n\nclient.join(11540, 'stackexchange.com')\n\ndef handler(event, server):\n    print(\"Received event type '{}' in room {} ({}) on server {}.\".format(event.shorthand, event.room.id,\n                                                                          event.room.name, server))\n\n\n# Redundant in this _particular_ case, but this handler will only receive events from\n# room 11540. You can use this principle to filter event handlers based on any property\n# available in the websocket event data dict - more on that later.\nclient.add_handler(handler, room_id=11540)\n```\n\n### Log in with cookies\nIf you save the cookies that you get from Stack Exchange, you can use those to log in again next time without going\nthrough credential authentication. This is not only faster, but also helps to avoid getting hit with CAPTCHAs, which\nare a massive pain.\n\nSpecify `cookie_file` in your call to `ChatClient.login` to do this. If the file exists and is a valid cookie jar, it\nwill be applied to the client's session. The `login` call returns this logged-in session - you are responsible for\nsaving the cookies, so after your first credential auth you'll want to make sure you pickle and save them.\n\n```python\nimport stackl\nimport pickle\n\n\nclient = stackl.ChatClient()\nsession = client.login('me@example.com', 'secure-password123', cookie_file='cookies.p')\n\nwith open('cookies.p', 'wb') as f:\n    pickle.dump(session.cookies, f, protocol=pickle.HIGHEST_PROTOCOL)\n```\n\n### Filter event handlers\nIf you want certain event handlers to only receive certain types of event, you can set filters for this when you add\nthe handler (via `ChatClient.add_handler`). You can filter based on any property that is sent in the WebSocket event\ndata - for a message, this will include `message_id`, `room_id`, `user_id`, etc - you may have to use your browser's\ndeveloper tools to figure out which fields you want, because I don't know what they all are.\n\n```python\n# Only messages in room 11540 by user 121520\nclient.add_handler(handler, room_id=11540, user_id=121520)\n\n# Only message-edited events, no other types\nclient.add_handler(handler, event_type=2)\n```\n\n---\n\nFor more details on the API available, see the API documentation or take a look at the code.\n\n## Contributing\nContributions are welcome. Send me a PR if you have a contribution you want to make. For major changes or API changes,\nit's best to open an issue to discuss it first. In particular, anything that would require an increment of the major\nversion number _must_ be discussed, but don't use that as an absolute - use your common sense and if in doubt, open an\nissue first.\n\nBy making a contribution you agree to license the contributed work under the MIT license and declare that you are\nlegally entitled to grant the said license.\n\n## License\nStackl is licensed under the [MIT license](https://github.com/ArtOfCode-/stackl/blob/master/LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartofcode-%2Fstackl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartofcode-%2Fstackl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartofcode-%2Fstackl/lists"}