{"id":13653863,"url":"https://github.com/libkeepass/pykeepass","last_synced_at":"2025-10-21T13:09:48.474Z","repository":{"id":42479972,"uuid":"69806239","full_name":"libkeepass/pykeepass","owner":"libkeepass","description":"Python library to interact with keepass databases (supports KDBX3 and KDBX4)","archived":false,"fork":false,"pushed_at":"2025-03-06T00:40:45.000Z","size":1001,"stargazers_count":440,"open_issues_count":35,"forks_count":97,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-09T02:46:47.209Z","etag":null,"topics":["hacktoberfest","kdbx","keepass","password-manager","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pykeepass/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libkeepass.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","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":"2016-10-02T15:54:03.000Z","updated_at":"2025-04-01T01:37:03.000Z","dependencies_parsed_at":"2023-11-14T23:28:57.653Z","dependency_job_id":"a39c7750-66a4-48bc-9d9e-9c41a6893714","html_url":"https://github.com/libkeepass/pykeepass","commit_stats":{"total_commits":366,"total_committers":37,"mean_commits":9.891891891891891,"dds":0.5765027322404371,"last_synced_commit":"20ab6547ba3afc7b2a379b2dbaf541bdd54accff"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libkeepass%2Fpykeepass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libkeepass%2Fpykeepass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libkeepass%2Fpykeepass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libkeepass%2Fpykeepass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libkeepass","download_url":"https://codeload.github.com/libkeepass/pykeepass/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250385303,"owners_count":21421893,"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":["hacktoberfest","kdbx","keepass","password-manager","python"],"created_at":"2024-08-02T02:01:19.324Z","updated_at":"2025-10-21T13:09:48.442Z","avatar_url":"https://github.com/libkeepass.png","language":"Python","readme":"# pykeepass\n\n\u003ca href=\"https://github.com/libkeepass/pykeepass/actions/workflows/ci.yaml\"\u003e\u003cimg src=\"https://github.com/libkeepass/pykeepass/actions/workflows/ci.yaml/badge.svg\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://libkeepass.github.io/pykeepass\"\u003e\u003cimg src=\"https://readthedocs.org/projects/pykeepass/badge/?version=latest\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://matrix.to/#/%23pykeepass:matrix.org\"\u003e\u003cimg src=\"https://img.shields.io/badge/chat-%23pykeepass-green\"/\u003e\u003c/a\u003e\n    \nThis library allows you to write entries to a KeePass database.\n\nCome chat at [#pykeepass:matrix.org](https://matrix.to/#/%23pykeepass:matrix.org) on Matrix.\n\n# Installation\n\n``` bash\nsudo apt install python3-lxml\npip install pykeepass\n```\n\n# Quickstart\n\nGeneral database manipulation\n\n``` python\nfrom pykeepass import PyKeePass\n\n# load database\n\u003e\u003e\u003e kp = PyKeePass('db.kdbx', password='somePassw0rd')\n\n# get all entries\n\u003e\u003e\u003e kp.entries\n[Entry: \"foo_entry (myusername)\", Entry: \"foobar_entry (myusername)\", ...]\n\n# find any group by its name\n\u003e\u003e\u003e group = kp.find_groups(name='social', first=True)\n\n# get the entries in a group\n\u003e\u003e\u003e group.entries\n[Entry: \"social/facebook (myusername)\", Entry: \"social/twitter (myusername)\"]\n\n# find any entry by its title\n\u003e\u003e\u003e entry = kp.find_entries(title='facebook', first=True)\n\n# retrieve the associated password and OTP information\n\u003e\u003e\u003e entry.password\n's3cure_p455w0rd'\n\u003e\u003e\u003e entry.otp\notpauth://totp/test:lkj?secret=TEST%3D%3D%3D%3D\u0026period=30\u0026digits=6\u0026issuer=test\n\n# update an entry\n\u003e\u003e\u003e entry.notes = 'primary facebook account'\n\n# create a new group\n\u003e\u003e\u003e group = kp.add_group(kp.root_group, 'email')\n\n# create a new entry\n\u003e\u003e\u003e kp.add_entry(group, 'gmail', 'myusername', 'myPassw0rdXX')\nEntry: \"email/gmail (myusername)\"\n\n# save database\n\u003e\u003e\u003e kp.save()\n```\n\nFinding and manipulating entries\n\n``` python\n# add a new entry to the Root group\n\u003e\u003e\u003e kp.add_entry(kp.root_group, 'testing', 'foo_user', 'passw0rd')\nEntry: \"testing (foo_user)\"\n\n# add a new entry to the social group\n\u003e\u003e\u003e group = kp.find_groups(name='social', first=True)\n\u003e\u003e\u003e entry = kp.add_entry(group, 'testing', 'foo_user', 'passw0rd')\nEntry: \"testing (foo_user)\"\n\n# save the database\n\u003e\u003e\u003e kp.save()\n\n# delete an entry\n\u003e\u003e\u003e kp.delete_entry(entry)\n\n# move an entry\n\u003e\u003e\u003e kp.move_entry(entry, kp.root_group)\n\n# save the database\n\u003e\u003e\u003e kp.save()\n\n# change creation time\n\u003e\u003e\u003e from datetime import datetime, timezone\n\u003e\u003e\u003e entry.ctime = datetime(2023, 1, 1, tzinfo=timezone.utc)\n\n# update modification or access time\n\u003e\u003e\u003e entry.touch(modify=True)\n\n# save entry history\n\u003e\u003e\u003e entry.save_history()\n```\n\nFinding and manipulating groups\n\n``` python\n\u003e\u003e\u003e kp.groups\n[Group: \"foo\", Group \"foobar\", Group: \"social\", Group: \"social/foo_subgroup\"]\n\n\u003e\u003e\u003e kp.find_groups(name='foo', first=True)\nGroup: \"foo\"\n\n\u003e\u003e\u003e kp.find_groups(name='foo.*', regex=True)\n[Group: \"foo\", Group \"foobar\"]\n\n\u003e\u003e\u003e kp.find_groups(path=['social'], regex=True)\n[Group: \"social\", Group: \"social/foo_subgroup\"]\n\n\u003e\u003e\u003e kp.find_groups(name='social', first=True).subgroups\n[Group: \"social/foo_subgroup\"]\n\n\u003e\u003e\u003e kp.root_group\nGroup: \"/\"\n\n# add a new group to the Root group\n\u003e\u003e\u003e group = kp.add_group(kp.root_group, 'social')\n\n# add a new group to the social group\n\u003e\u003e\u003e group2 = kp.add_group(group, 'gmail')\nGroup: \"social/gmail\"\n\n# save the database\n\u003e\u003e\u003e kp.save()\n\n# delete a group\n\u003e\u003e\u003e kp.delete_group(group)\n\n# move a group\n\u003e\u003e\u003e kp.move_group(group2, kp.root_group)\n\n# save the database\n\u003e\u003e\u003e kp.save()\n\n# change creation time\n\u003e\u003e\u003e from datetime import datetime, timezone\n\u003e\u003e\u003e group.ctime = datetime(2023, 1, 1, tzinfo=timezone.utc)\n\n# update modification or access time\n\u003e\u003e\u003e group.touch(modify=True)\n```\n\nAttachments\n\n``` python\n\u003e\u003e\u003e e = kp.add_entry(kp.root_group, title='foo', username='', password='')\n\n# add attachment data to the db\n\u003e\u003e\u003e binary_id = kp.add_binary(b'Hello world')\n\n\u003e\u003e\u003e kp.binaries\n[b'Hello world']\n\n# add attachment reference to entry\n\u003e\u003e\u003e a = e.add_attachment(binary_id, 'hello.txt')\n\u003e\u003e\u003e a\nAttachment: 'hello.txt' -\u003e 0\n\n# access attachments\n\u003e\u003e\u003e a\nAttachment: 'hello.txt' -\u003e 0\n\u003e\u003e\u003e a.id\n0\n\u003e\u003e\u003e a.filename\n'hello.txt'\n\u003e\u003e\u003e a.data\nb'Hello world'\n\u003e\u003e\u003e e.attachments\n[Attachment: 'hello.txt' -\u003e 0]\n\n# list all attachments in the database\n\u003e\u003e\u003e kp.attachments\n[Attachment: 'hello.txt' -\u003e 0]\n\n# search attachments\n\u003e\u003e\u003e kp.find_attachments(filename='hello.txt')\n[Attachment: 'hello.txt** -\u003e 0]\n\n# delete attachment reference\n\u003e\u003e\u003e e.delete_attachment(a)\n\n# or, delete both attachment reference and binary\n\u003e\u003e\u003e kp.delete_binary(binary_id**\n```\n\nOTP codes\n\n``` python\n# find an entry which has otp attribute\n\u003e\u003e\u003e e = kp.find_entries(otp='.*', regex=True, first=True)\n\u003e\u003e\u003e import pyotp\n\u003e\u003e\u003e pyotp.parse_uri(e.otp).now()\n799270\n```\n\n\n# Tests and Debugging\n\nRun tests with `python tests/tests.py` or `python tests/tests.py SomeSpecificTest`\n\nEnable debugging when doing tests in console:\n\n``` python\n\u003e\u003e\u003e from pykeepass.pykeepass import debug_setup\n\u003e\u003e\u003e debug_setup()\n\u003e\u003e\u003e kp.entries[0]\nDEBUG:pykeepass.pykeepass:xpath query: //Entry\nDEBUG:pykeepass.pykeepass:xpath query: (ancestor::Group)[last()]\nDEBUG:pykeepass.pykeepass:xpath query: (ancestor::Group)[last()]\nDEBUG:pykeepass.pykeepass:xpath query: String/Key[text()=\"Title\"]/../Value\nDEBUG:pykeepass.pykeepass:xpath query: String/Key[text()=\"UserName\"]/../Value\nEntry: \"root_entry (foobar_user)\"\n```\n\n","funding_links":[],"categories":["API libraries","Python"],"sub_categories":["Other clients"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibkeepass%2Fpykeepass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibkeepass%2Fpykeepass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibkeepass%2Fpykeepass/lists"}