A flat file database for json objects.
Project description
# jsondb [![Build Status][travis-image]][travis-build]
This is a utility for managing content in a database which stores
content in JSON format.
## Installation
This package can be installed from [PyPi](https://pypi.python.org/pypi/jsondatabase) by running:
```bash
pip install jsondatabase
```
Note, the package name and the import name are different.
Import the package using `import jsondb`.
## Usage
```python
from jsondb.db import Database
db = Database("mydata.db")
```
The database has an attribute which works similar to
[jQuery's `data`][jquery-data] attribute.
```python
# Getting all data
db = Database("mydata.db")
print(db.data())
```
```python
# Getting a stored value
db = Database("mydata.db")
print(db.data(key="user_count"))
```
**It is important to note that a key will be created regardless of whether it
exists as long as a value is provided.** The database has the same functionality
as a dictionary.
```python
# Setting a value
db = Database("mydata.db")
db.data(key="user_count", value=241)
```
```python
# Passing in a dictionary value
db = Database("mydata.db")
data = {
"user_id": 234565,
"user_name": "AwesomeUserName",
"is_moderator": True,
}
db.data(dictionary=data)
```
```python
# Deleting a value
db = Database("mydata.db")
db.delete("my_key")
```
The database also supports a dictionary-like syntax for retrieving, setting, and
removing values.
```python
db = Database("mydata.db")
# Retrieving a value
value = db["key"]
# Setting a value
db["key"] = value
# Removing a key
del db["key"]
# Checking if a key exists
"key" in db
```
## Performance
If performance is an issue with large databases then the `python-cjson` module
can be installed. jsondb will automatically detect this and use cjson instead.
[jquery-data]: http://api.jquery.com/data/
[travis-build]: https://travis-ci.org/gunthercox/jsondb
[travis-image]: https://travis-ci.org/gunthercox/jsondb.svg
History
-------
`See release notes
<https://github.com/gunthercox/jsondb/releases>`_
This is a utility for managing content in a database which stores
content in JSON format.
## Installation
This package can be installed from [PyPi](https://pypi.python.org/pypi/jsondatabase) by running:
```bash
pip install jsondatabase
```
Note, the package name and the import name are different.
Import the package using `import jsondb`.
## Usage
```python
from jsondb.db import Database
db = Database("mydata.db")
```
The database has an attribute which works similar to
[jQuery's `data`][jquery-data] attribute.
```python
# Getting all data
db = Database("mydata.db")
print(db.data())
```
```python
# Getting a stored value
db = Database("mydata.db")
print(db.data(key="user_count"))
```
**It is important to note that a key will be created regardless of whether it
exists as long as a value is provided.** The database has the same functionality
as a dictionary.
```python
# Setting a value
db = Database("mydata.db")
db.data(key="user_count", value=241)
```
```python
# Passing in a dictionary value
db = Database("mydata.db")
data = {
"user_id": 234565,
"user_name": "AwesomeUserName",
"is_moderator": True,
}
db.data(dictionary=data)
```
```python
# Deleting a value
db = Database("mydata.db")
db.delete("my_key")
```
The database also supports a dictionary-like syntax for retrieving, setting, and
removing values.
```python
db = Database("mydata.db")
# Retrieving a value
value = db["key"]
# Setting a value
db["key"] = value
# Removing a key
del db["key"]
# Checking if a key exists
"key" in db
```
## Performance
If performance is an issue with large databases then the `python-cjson` module
can be installed. jsondb will automatically detect this and use cjson instead.
[jquery-data]: http://api.jquery.com/data/
[travis-build]: https://travis-ci.org/gunthercox/jsondb
[travis-image]: https://travis-ci.org/gunthercox/jsondb.svg
History
-------
`See release notes
<https://github.com/gunthercox/jsondb/releases>`_
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jsondatabase-0.0.6.tar.gz
(7.9 kB
view hashes)
Built Distribution
Close
Hashes for jsondatabase-0.0.6-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cb6c3ce81aaee1a66a3346881f2015c450d2f24b76e08e68da5c169ff2a56fe |
|
MD5 | e1eca76c20af94c6d3d240ad6d133a21 |
|
BLAKE2b-256 | 56ea5a930d20ded30858208e7b027362ad58b0bc1ff8aa4ed7f333eb5a11371e |