Skip to main content
https://badge.fury.io/py/labml-db.svg https://pepy.tech/badge/labml-db

LabML DB

LabML DB is a minimalistic ORM database that uses JSON, YAML or Pickle files. It uses Python typehints as much as possible to help with static checking, and IDE features like autocompletion.

You can install this package using PIP.

pip install labml_db

Example

from labml_db import Model, Index


class Project(Model['Project']):
    name: str
    experiments: int

    @classmethod
    def defaults(cls):
        return dict(name='', experiments=0)


class User(Model['User']):
    name: str
    projects: List[Key[Project]]
    # This is an optional property, will automatically default to None
    occupation: Optional[str]

    @classmethod
    def defaults(cls):
        # Name is not in defaults and not optional.
        # It will be considered a required property
        return dict(projects=[])


class UsernameIndex(Index['User']):
    pass

You can configure it to use JSON/YAML/Pickle files

Model.set_db_drivers([
    FileDbDriver(PickleSerializer(), User, Path('./data/user')),
    FileDbDriver(YamlSerializer(), Project, Path('./data/project'))
])
Index.set_db_drivers([
    FileIndexDbDriver(JsonSerializer(), UsernameIndex, Path('./data/UserNameIndex.yaml'))
])

You can user get_all and Key.load to retrieve models, and save to save models.

proj = Project(name='nlp')
user = User(name='John')
user.projects.append(proj.key)
user.occupation = 'test'
user.save()
proj.save()

keys = User.get_all()
print([k.load() for k in keys])
keys = Project.get_all()
print([k.load() for k in keys])

And index is a hash-map between strings and keys.

user_key = UsernameIndex.get('John')
if not user_key:
    user = User(name='John')
    user.save()
    UsernameIndex.set(user.name, user.key)
else:
    print(user_key.load())

Metadata

Release files for labml-db 0.0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for labml-db 0.0.15
File Size Uploaded
labml_db-0.0.15.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for labml-db 0.0.15
File Interpreter ABI Platform
labml_db-0.0.15-py3-none-any.whl Python 3 none any Details

Total release size: 22.4 kB

Release files / labml_db-0.0.15.tar.gz

Download URL labml_db-0.0.15.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
89d3a1e26a7171cc21a05b0c97830b91644b63215692312099aa849e89e3a1b9
BLAKE2b-256 checksum
How to use checksums
b4e767168274c9cb3deb6ece12f5fc5d812e2629f66c9c223f664479723ba488
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

Release files / labml_db-0.0.15-py3-none-any.whl

Download URL labml_db-0.0.15-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
672aa0a1aa93f9d4d6be62658b391a06c241e56d410576f997bd7141b7653e91
BLAKE2b-256 checksum
How to use checksums
c4a9e6f1a61ceb87ab0740300b88800517f8c870fe0080497b046704b0217acc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.0.15 This release

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page