py_dataset is a Python wrapper for the dataset command line tools. It replaces the depreciated libdataset a C shared library starting with the dataset 2.2.x release.
This package wraps all dataset operations such as initialization of collections, creation, reading, updating and deleting JSON objects in the collection. Some of its enhanced features include the ability to generate data frames as well as the ability to import and export JSON objects to and from CSV files.
py_dataset is release under a BSD style license.
dataset supports
See docs for detials.
dataset has many limitations, some are listed below
Available via pip pip install py_dataset
or by
downloading this repo and typing python setup.py install
.
This repo includes dataset shared C libraries compiled for Windows, Mac,
and Linux and the appripriate library will be used automatically.
This module provides the functionality of the dataset command line tool as a Python 3.10 module. Once installed try out the following commands to see if everything is in order (or to get familier with dataset).
The “#” comments don’t have to be typed in, they are there to explain the commands as your type them. Start the tour by launching Python3 in interactive mode.
python3
Then run the following Python commands.
from py_dataset import dataset
# Almost all the commands require the collection_name as first paramter,
# we're storing that name in c_name for convienence.
= "a_tour_of_dataset.ds"
c_name
# Let's create our a dataset collection. We use the method called
# 'init' it returns True on success or False otherwise.
dataset.init(c_name)
# Let's check to see if our collection to exists, True it exists
# False if it doesn't.
dataset.status(c_name)
# Let's count the records in our collection (should be zero)
= dataset.count(c_name)
cnt print(cnt)
# Let's read all the keys in the collection (should be an empty list)
= dataset.keys(c_name)
keys print(keys)
# Now let's add a record to our collection. To create a record we need to know
# this collection name (e.g. c_name), the key (most be string) and have a
# record (i.e. a dict literal or variable)
= "one"
key = {"one": 1}
record # If create returns False, we can check the last error message
# with the 'error_message' method
if not dataset.create(c_name, key, record):
print(dataset.error_message())
# Let's count and list the keys in our collection, we should see a count of '1' and a key of 'one'
dataset.count(c_name)= dataset.keys(c_name)
keys print(keys)
# We can read the record we stored using the 'read' method.
= dataset.read(c_name, key)
new_record, err if err != '':
print(err)
else:
print(new_record)
# Let's modify new_record and update the record in our collection
"two"] = 2
new_record[if not dataset.update(c_name, key, new_record):
print(dataset.error_message())
# Let's print out the record we stored using read method
# read returns a touple so we're printing the first one.
print(dataset.read(c_name, key)[0])
# Now let's query the collection.
= f'''select src from {c_name} order by created desc'''
sql_stmt print(dataset.query(c_name, sql_stmt))
# Finally we can remove (delete) a record from our collection
if not dataset.delete(c_name, key):
print(dataset.error_message())
# We should not have a count of Zero records
= dataset.count(c_name)
cnt print(cnt)