{"id":28447977,"url":"https://github.com/labmlai/db","last_synced_at":"2025-06-30T15:32:22.339Z","repository":{"id":43894347,"uuid":"304533703","full_name":"labmlai/db","owner":"labmlai","description":"Minimalistic Object-Relational Mapper for JSON/YAML/Pickle file based db","archived":false,"fork":false,"pushed_at":"2023-11-14T08:26:26.000Z","size":75,"stargazers_count":6,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-06T12:08:20.407Z","etag":null,"topics":["database","json","minimal","orm","pickle","python","yaml"],"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/labmlai.png","metadata":{"files":{"readme":"readme.rst","changelog":null,"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}},"created_at":"2020-10-16T06:00:42.000Z","updated_at":"2024-03-20T09:37:35.000Z","dependencies_parsed_at":"2023-11-14T09:31:05.633Z","dependency_job_id":"7a2da9c3-a42b-43a4-b9f3-2d39df61a6d7","html_url":"https://github.com/labmlai/db","commit_stats":{"total_commits":52,"total_committers":3,"mean_commits":"17.333333333333332","dds":"0.11538461538461542","last_synced_commit":"936a2787a53c5bc82da92471bc3befdd1b25ab97"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/labmlai/db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labmlai%2Fdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labmlai%2Fdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labmlai%2Fdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labmlai%2Fdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/labmlai","download_url":"https://codeload.github.com/labmlai/db/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labmlai%2Fdb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262800736,"owners_count":23366427,"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":["database","json","minimal","orm","pickle","python","yaml"],"created_at":"2025-06-06T12:08:18.407Z","updated_at":"2025-06-30T15:32:22.330Z","avatar_url":"https://github.com/labmlai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. image:: https://badge.fury.io/py/labml-db.svg\n    :target: https://badge.fury.io/py/labml-db\n.. image:: https://pepy.tech/badge/labml-db\n    :target: https://pepy.tech/project/labml-db\n\nLabML DB\n========\n\nLabML DB is a minimalistic ORM database that uses JSON, YAML or Pickle files.\nIt uses Python typehints as much as possible to help with static checking,\nand IDE features like autocompletion.\n\nYou can install this package using PIP.\n\n.. code-block:: console\n\n    pip install labml_db\n\n\nExample\n^^^^^^^\n\n.. code-block:: python\n\n    from labml_db import Model, Index\n\n\n    class Project(Model['Project']):\n        name: str\n        experiments: int\n\n        @classmethod\n        def defaults(cls):\n            return dict(name='', experiments=0)\n\n\n    class User(Model['User']):\n        name: str\n        projects: List[Key[Project]]\n        # This is an optional property, will automatically default to None\n        occupation: Optional[str]\n\n        @classmethod\n        def defaults(cls):\n            # Name is not in defaults and not optional.\n            # It will be considered a required property\n            return dict(projects=[])\n\n\n    class UsernameIndex(Index['User']):\n        pass\n\nYou can configure it to use JSON/YAML/Pickle files\n\n.. code-block:: python\n\n    Model.set_db_drivers([\n        FileDbDriver(PickleSerializer(), User, Path('./data/user')),\n        FileDbDriver(YamlSerializer(), Project, Path('./data/project'))\n    ])\n    Index.set_db_drivers([\n        FileIndexDbDriver(JsonSerializer(), UsernameIndex, Path('./data/UserNameIndex.yaml'))\n    ])\n\nYou can user `get_all` and `Key.load` to retrieve models, and `save` to save models.\n\n.. code-block:: python\n\n    proj = Project(name='nlp')\n    user = User(name='John')\n    user.projects.append(proj.key)\n    user.occupation = 'test'\n    user.save()\n    proj.save()\n\n    keys = User.get_all()\n    print([k.load() for k in keys])\n    keys = Project.get_all()\n    print([k.load() for k in keys])\n\nAnd index is a hash-map between strings and keys.\n\n.. code-block:: python\n\n    user_key = UsernameIndex.get('John')\n    if not user_key:\n        user = User(name='John')\n        user.save()\n        UsernameIndex.set(user.name, user.key)\n    else:\n        print(user_key.load())\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabmlai%2Fdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flabmlai%2Fdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabmlai%2Fdb/lists"}