{"id":24790397,"url":"https://github.com/hk-mattew/ptb-persistence","last_synced_at":"2025-03-24T13:14:42.510Z","repository":{"id":255472650,"uuid":"849885047","full_name":"HK-Mattew/ptb-persistence","owner":"HK-Mattew","description":"Python data persistence library for Telegram bot developed using PTB.","archived":false,"fork":false,"pushed_at":"2024-09-11T12:21:50.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T18:15:49.784Z","etag":null,"topics":["basepersistence","mongodb","ptb-persistence","python-telegram-bot","telegram-bot","telegram-bot-api"],"latest_commit_sha":null,"homepage":"","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/HK-Mattew.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-30T12:54:30.000Z","updated_at":"2024-09-11T12:21:53.000Z","dependencies_parsed_at":"2024-09-09T21:35:49.839Z","dependency_job_id":null,"html_url":"https://github.com/HK-Mattew/ptb-persistence","commit_stats":null,"previous_names":["hk-mattew/ptb-persistence"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HK-Mattew%2Fptb-persistence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HK-Mattew%2Fptb-persistence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HK-Mattew%2Fptb-persistence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HK-Mattew%2Fptb-persistence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HK-Mattew","download_url":"https://codeload.github.com/HK-Mattew/ptb-persistence/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245276178,"owners_count":20588894,"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":["basepersistence","mongodb","ptb-persistence","python-telegram-bot","telegram-bot","telegram-bot-api"],"created_at":"2025-01-29T18:15:51.738Z","updated_at":"2025-03-24T13:14:42.425Z","avatar_url":"https://github.com/HK-Mattew.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Persistent data for lib PTB\n\nPTBPersistence is a Python library to deal with developed bot data persistence using lib [PTB](https://github.com/python-telegram-bot/python-telegram-bot).\n\nDeveloped to support multiple data storage.\n\nData store supported at the moment:\n- MongoDB\n\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install.\n\n```bash\npip install git+https://github.com/HK-Mattew/ptb-persistence.git\n```\n\nUse Poetry to install.\n\n```bash\npoetry add git+https://github.com/HK-Mattew/ptb-persistence.git\n```\n\n## Usage\n\n```python\nfrom ptb_persistence import PTBPersistence\n\nfrom ptb_persistence.datastores.mongodb import MongoDBDataStore\nfrom telegram.ext import Application\n\n\ndata_store = MongoDBDataStore(\n    ...\n)\n\nptb_persistence = PTBPersistence(\n    data_store=data_store\n)\n\napplication = (\n    Application\n    .builder()\n    .token(\"\u003cbot-token\u003e\")\n    .persistence(ptb_persistence).build()\n)\n\n```\n\n## Support for multiple Workers/Processes\nThis library is designed to work well with multi-worker bots. Typically bots that run in webhook mode and use load balancers between multiple instances of the same bot.\n\n### Conversational data persistence\nCurrently, PTB does not have a method like refresh_conversation_data(...). And this prevents us from working with persistent conversations across multiple workers/processes.\n\nHere I work around this (Famous Hack) 😄,\nI created a custom Application class where I implement some logic to update conversation data. And this allows us to work with conversation data shared between multiple workers/processes.\n\nSee the custom CustomApplication class (and also more details): [Here](https://github.com/HK-Mattew/ptb-persistence/blob/main/ptb_persistence/utils/ptb.py)\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first\nto discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhk-mattew%2Fptb-persistence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhk-mattew%2Fptb-persistence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhk-mattew%2Fptb-persistence/lists"}