Sunshine
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
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| SunshineDB-1.5.tar.gz | 5.4 kB | Without provenance | Details for SunshineDB-1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| SunshineDB-1.5-py3-none-any.whl | Python 3 | none | any | Details for SunshineDB-1.5-py3-none-any.whl |
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
|
Security for SunshineDB 1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.