A package that provides tools for interacting with databases when working with alfred3 experiments.
Project description
alfred3_dbtools
This module provides additional tools for working with databases in the context of alfred experiments (see alfred on GitHub).
Installation
pip install alfred3_dbtools
Usage
To import the tools for working with mongodb, include this statement at the beginning of your script:
from alfred3_dbtools import mongotools
You can then access the classes provided in the module:
mongotools.MongoDBConnector
can be used to establish an independent connection to an instance ofpymongo.MongoClient
. Access to the client is provided viamongotools.MongoDBConnector.db
. Depending on how theMongoDBConnector
was initialised, this will return either a database instance or a specific collection inside a database.- Parameters:
host
,port
,username
,password
,database
,collection
(defaults toNone
),auth_source
(defaults to "admin"),ssl
(defaults toFalse
),ca_file
(defaults toNone
). Seehelp(mongotools.MongoDBConnector)
for details.
- Parameters:
mongotools.ExpMongoDBConnector
can be used to establish a connection to an experiments' MongoDBs.- The constructor takes one parameter:
experiment
, which needs to be an alfred experiment. Seehelp(mongotools.ExpMongoDBConnector)
for details. mongotools.ExpMongoDBConnector.db
will return the MongoDB collection of theMongoSavingAgent
with the lowest activation level (i.e. the primaryMongoSavingAgent
). It will raise aValueError
, if the lowest activation level is occupied by two or moreMongoSavingAgent
s.mongotools.ExpMongoDBConnector.list_agents
will return a list of allMongoSavingAgent
s added to the experiment.
- The constructor takes one parameter:
Refer to the pymongo documentation for further details on how to interact with the clients.
Example of using ExpMongoDBConnector
from alfred import Experiment
from alfred3_dbtools import mongotools
def generate_experiment(self, config=None):
exp = Experiment(config=config)
db_connector = mongotools.ExpMongoDBConnector(exp)
db = db_connector.db
first_exp = db.find_one({"exp_title": "Title goes here"})
return exp
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
alfred3_dbtools-0.1.0.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for alfred3_dbtools-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 538a0a952d9ef97ee206cad281622227dec964bcd6bed15d95087d26e2541339 |
|
MD5 | d1710126e7d9da6e6ae6559632253056 |
|
BLAKE2b-256 | ce0a5a619bab2333eee003b82cae5dad0b7cff73837f5be69c5a0f8ca97dd730 |