{"id":29792570,"url":"https://github.com/mattewid/ptb-persistence","last_synced_at":"2026-05-15T12:31:41.093Z","repository":{"id":255472650,"uuid":"849885047","full_name":"mattewid/ptb-persistence","owner":"mattewid","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-04-26T22:31:17.279Z","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/mattewid.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,"zenodo":null}},"created_at":"2024-08-30T12:54:30.000Z","updated_at":"2024-09-11T12:21:53.000Z","dependencies_parsed_at":"2025-04-26T22:31:22.539Z","dependency_job_id":"add1059a-efcf-4a2a-8f6b-ef3f4ee3239f","html_url":"https://github.com/mattewid/ptb-persistence","commit_stats":null,"previous_names":["hk-mattew/ptb-persistence","mattewid/ptb-persistence"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mattewid/ptb-persistence","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattewid%2Fptb-persistence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattewid%2Fptb-persistence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattewid%2Fptb-persistence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattewid%2Fptb-persistence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattewid","download_url":"https://codeload.github.com/mattewid/ptb-persistence/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattewid%2Fptb-persistence/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267451250,"owners_count":24089302,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-07-28T01:40:07.184Z","updated_at":"2026-05-02T09:34:23.668Z","avatar_url":"https://github.com/mattewid.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%2Fmattewid%2Fptb-persistence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattewid%2Fptb-persistence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattewid%2Fptb-persistence/lists"}