Skip to main content

Sunshine

Sunshine Logo

Lightweight json-database library for Python


Installing database library

pip install SunshineDB

Class

Sunshine - database management class.

Has the following set of methods:

0. push()
1. all()
2. get()
3. update()
4. contains()
5. delete()
6. drop()
7. backup()


Creating database

You just need to create an instance of the Sunshine-class, passing the path to the json-file as an argument.

For example,

from SunshineDB import Sunshine

database: Sunshine = Sunshine('../databases/database.json')

Methods

Method examples will be given using the database variable we set.

push()

Adds an object with the given fields to the database.
Requires one argument:

  • data_to_push (dictionary[string, any]) - the key-value dictionary to be added to the database.

Returns ID.

identifier: int = database.push(
    {
        'name'       : 'Bertram Gilfoyle',
        'job'        : 'Pied Piper Inc.',
        'occupation' : 'Vice President Of Architecture'
    }
)

print(identifier) 
# output >> 22104564398807 
#           ^^^^^^^^^^^^^^
# ID is 14-digit integer

all()

Returns all database objects.

data: list[dict[str, any]] = database.all()

print(data)
# output >> 
# [
#   {
#       'id': 22104564398807, 
#       'name': 'Bertram Gilfoyle', 
#       'job': 'Pied Piper Inc.', 
#       'occupation': 'Vice President Of Architecture'
#   }
# ]

get()

Returns a database object using a query, or returns the number of given elements in the first one up to the number specified in the count argument.
Requires two arguments:

  • query (dictionary[string, any]) - a key-value dictionary that will be used to select elements,
  • count (integer) - the number of requested elements.

You cannot use both arguments together.

data: list[dict[str, any]] = database.get(
    query = {
        'job' : 'Pied Piper Inc.'
    }
)

print(data)
# output >> 
# [
#   {
#       'id': 22104564398807, 
#       'name': 'Bertram Gilfoyle', 
#       'job': 'Pied Piper Inc.', 
#       'occupation': 'Vice President Of Architecture'
#   }
# ]

# And the same will be displayed if you call the get-method like this
data: list[dict[str, any]] = database.get(count = 1)

update()

Updates a database object with an ID.
Requires two arguments:

  • id (14-digit integer) - numeric identifier,
  • data_to_update (dictionary[string, any]) - the key-value dictionary that will be updated in the database object.

database.update(
    22104564398807, 
    {
        'occupation' : 'Network engineer'
    }
)
# changed to >> 
# [
#   {
#       'id': 22104564398807, 
#       'name': 'Bertram Gilfoyle', 
#       'job': 'Pied Piper Inc.', 
#       'occupation': 'Network engineer'
#   }
# ]

contains()

Checks by query, if an element is contained in the database.
Requires two arguments:

  • key (string),
  • value (any).

These arguments will be searched in the database.

Returns boolean.

data: bool = database.contains('name', 'Bertram Gilfoyle')
print(data)
# output >> True
#           ^^^^
# contains-method returns boolean

data: bool = database.contains('name', 'Dinesh Chugtai')
print(data)
# output >> False

delete()

Removes the object with the given ID from the database.
Requires one argument:

  • id (14-digit integer) - numeric identifier,

database.delete(22104564398807)

# database-file >>
# {
#   "data": []
# }

drop()

Removes all objects from the database.


database.drop()

# database-file >>
# {
#   "data": []
# }

backup()

Creates a database backup at the given path.
Requires one argument:

  • path (string) - path to the folder where the backup-file will be saved.

database.backup('../databases/backups/')



Author

     _      _  _               _ _   
  __| | ___| || |   ___  _   _| | |_ 
 / _` |/ _ \ || |_ / _ \| | | | | __|
| (_| |  __/__   _| (_) | |_| | | |_ 
 \__,_|\___|  |_|  \___/ \__,_|_|\__|

Thank you a lot!


How to reach me

Telegram Badge Gmail Badge

Metadata

Release files for SunshineDB 1.5

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

Source distribution (sdist)

Source distribution for SunshineDB 1.5
File Size Uploaded
SunshineDB-1.5.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for SunshineDB 1.5
File Interpreter ABI Platform
SunshineDB-1.5-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / SunshineDB-1.5.tar.gz

Download URL SunshineDB-1.5.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e9e7369844f7bd49f136d6358caecb7a53f0a6116b44baa8cbe882f327f8e8c7
BLAKE2b-256 checksum
How to use checksums
ed1f6db4541760f99a691070ae09bac65eb62d5e426ce640e9939171b90872e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / SunshineDB-1.5-py3-none-any.whl

Download URL SunshineDB-1.5-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57184584882ca0fbc6a4aec98c05ef8fce04d901769a57954dbd7462d83f9b11
BLAKE2b-256 checksum
How to use checksums
985acfa9cdbfc879d74367cc3e0cd3d0bcf0289f30587fc1363b72ed5a121382
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release history Release notifications | RSS feed

This release

1.5 This release

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

1 release file

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