Skip to main content

Logging into CouchDB.

Project description

CouchBed

CouchBed is a Python library that allows you to log your code execution into CouchDB. It provides a simple and convenient way to record settings, messages, and logs into a CouchDB database.

Installation

You can install CouchBed using pip:

pip install couchbed

Usage

First, import the CouchBed class from the couchbed module:

from couchbed import CouchBed

Create an instance of the CouchBed class, specifying the name of the CouchDB database as a parameter. By default, CouchBed uses the CouchDB URI provided by the PYTHON_COUCHBED environment variable. Alternatively, you can pass the URI as a parameter when creating the CouchBed instance. For each trial, you prepare a new book (CBBook).

couch = CouchBed("__DATABASE_NAME__")
book = couch.new_book()

Recording Settings

You can record settings by using the set method or by directly assigning values to keys in the CBBook instance.

book.set({"a": 1, "b": 2})
# or
book["key"] = "value"

Accessing Settings

You can access the recorded settings by using the CBBook instance as a dictionary.

print(book["a"])

Recording Messages

You can record messages by calling the CBBook instance as a function and passing the desired message as arguments.

book("Hello", 1, 2, 3)

Recording Logs

You can record logs by using the log method and passing a dictionary containing the log information.

book.log({"epoch": 1, "train_loss": 0.1, "val_loss": 0.15})

Saving Data

CouchBed automatically saves the data every 5 seconds if there are any changes. However, it's recommended to explicitly call the save method at the end of your program to ensure all the data is saved. Otherwise, the last 5-second data may be lost.

book.save()
# or
couch.save()

License

CouchBed 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

couchbed-0.2.0.tar.gz (4.3 kB view hashes)

Uploaded Source

Supported by

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