Skip to main content

A lightweight, JSON-based Python ORM library

Project description

tinyjsondb

tinyjsondb is a minimal Python ORM for working with JSON files as a simple database. It allows defining models with typed fields, creating, reading, updating, and deleting records, all stored in JSON.

Installation

pip install tinyjsondb

or from source:

git clone https://github.com/Waland2/tinyjsondb.git
cd tinyjsondb
pip install .

Quick Start

from tinyjsondb import Model, IntegerField, StringField, ListField

class User(Model):
    name = StringField(default="Anonymous")
    hobbies = ListField(default=[])

# Initialize the storage file and sync schema
User.sync()

# Create a record
User.objects.create(name="Alice", hobbies=["reading"])

# Get a record
user = User.objects.get(id=1)
print(user.name)  # Alice

# Update a record
user.update(name="Alice Wonderland")

# Delete a record
user.delete()
user = User.objects.get(id=1)
print(user is None)  # True

# Get all records
users = User.objects.all()

Overview

Model methods:

  • sync() - create or update the JSON file with data.
  • save() - insert or update the record.
  • update(**kwargs) - update fields and save.
  • delete() - remove the record.
  • pk() - return the primary key value.

Manager methods (Model.objects):

  • create(**kwargs) - insert a new record.
  • get(**kwargs) - return the first matching record or None.
  • get_or_create(**kwargs) - return an existing record or create it.
  • all() - return all records.
  • update(obj) - update an existing record.
  • delete(**kwargs) - remove a record by field values.
  • clear() - remove all records.

Field types

  • IntegerField() - integer field.
  • StringField() - string field.
  • ListField() - list field.
  • DictField() - dictionary field.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tinyjsondb-0.1.3.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tinyjsondb-0.1.3-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file tinyjsondb-0.1.3.tar.gz.

File metadata

  • Download URL: tinyjsondb-0.1.3.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for tinyjsondb-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a101962c3344253be954817ddab633ab4c5d705abf06a977a1d6595c657b1ef7
MD5 b90a69e4d5f0d085c003f98ffb72c694
BLAKE2b-256 e5ef10bbcd5974e56f3fb3adc1fa0a0aeb6c2eb091784d87f65a92c0a3fd60ed

See more details on using hashes here.

File details

Details for the file tinyjsondb-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: tinyjsondb-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for tinyjsondb-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 17761f7148bbe51a7eeeef0c9f5c227073017b83cd041f0e7b643594cb9e4ef5
MD5 c430b4f4f52975b23d3e675533212e55
BLAKE2b-256 8dc3ab4d7ff46fcf827a9bcbb3dc7bf89d9ba3f284ee46f2f311b6bf2ec7d1b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page