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
File details
Details for the file couchbed-0.2.0.tar.gz
.
File metadata
- Download URL: couchbed-0.2.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e208a3f9dc6766c92dd10023e1820aeb4cfe7e3d2d98455bb789174be71b046a |
|
MD5 | 6f55f3d371d89893f61b61560010ccf9 |
|
BLAKE2b-256 | c656d0dbee8f2f00d2ba507514914470554e4ab2d1222acd28e518822f952463 |