EthoPy Configuration Guide¶
What is local_conf.json?¶
The local_conf.json file stores device-specific settings that are unique to each computer or experimental setup. These are settings that:
- Are tied to your specific hardware (file paths, GPIO pins, database credentials)
- Need to be configured once per machine, not per experiment
Key distinction: Experimental parameters and data go in the database. Machine-specific settings go in local_conf.json.
How EthoPy is Configured¶
EthoPy reads its settings from one JSON configuration file, plus a small number of overrides that apply on top of it. There are four mechanisms in total:
| # | Mechanism | What it controls | Scope |
|---|---|---|---|
| 1 | ~/.ethopy/local_conf.json |
Everything: database, paths, logging, schemata, plugins, hardware | Default for every run on this machine |
| 2 | ethopy -c /path/to/conf.json |
Same as above, from a different file | A single run |
| 3 | Environment variable ETHOPY_PLUGIN_PATH |
Extra plugin directories only | The shell session |
Command-line flags (--log-level, --log-console) override individual logging settings for one run, but they are not a general configuration mechanism.
1. The default configuration file¶
With no other instruction, EthoPy loads:
- Mac/Linux:
~/.ethopy/local_conf.json - Windows:
%USERPROFILE%\.ethopy\local_conf.json
The file is read once, at import ethopy. If it does not exist, EthoPy runs entirely on its built-in defaults.
2. A different config file on the command line¶
Every EthoPy run can point at another file with -c / --config:
1 | |
This is the supported way to keep several configurations on one machine, one per rig, or one per database. The file must exist; EthoPy exits with an error if it does not.
Important: the custom file replaces the default one, it is not merged with ~/.ethopy/local_conf.json. Any key you leave out falls back to the built-in default, not to the value in your home-directory file. Custom config files should therefore be self-contained.
3. From Python¶
The configuration object is available as ethopy.local_conf and can be read anywhere in your own code, including plugins:
1 2 3 4 5 | |
get() resolves a key in this order, returning the first hit:
- A top-level key of the JSON file (
"source_path","SCHEMATA","Channels", ...) - A key inside
dj_local_conf(so"database.host"works without a prefix) - Dot notation walked through nested objects (
"logging.level") - The
defaultargument you passed, orNone
To load a different file explicitly — for example in a notebook or an export script:
1 2 3 4 | |
By itself this only affects the conf object. To make the rest of EthoPy (DataJoint connection, schema names, plugin manager) use it as well, apply it globally:
1 | |
update_global_config() re-points ethopy.local_conf, pushes dj_local_conf into DataJoint, replaces ethopy.SCHEMATA, and rebuilds the plugin manager from the new plugin_path. This is exactly what ethopy -c does internally.
The NWB exporter takes its own config_path argument for the same purpose — see Export to NWB.
4. Environment variables¶
EthoPy reads exactly one environment variable of its own:
ETHOPY_PLUGIN_PATH— a comma-separated list of extra plugin directories.
1 | |
There is no environment variable for the config file location — use ethopy -c instead.
Note that DataJoint's own environment variables (DJ_HOST, DJ_USER, DJ_PASS, ...) have no effect on EthoPy. EthoPy pushes its dj_local_conf block into dj.config at import, after DataJoint has read the environment, so the JSON file — or its default — wins in every case. Set database credentials in dj_local_conf, not in the environment.
Built-in Defaults¶
Any key absent from your configuration file is filled in with a default, so a minimal file is enough to get started. The defaults are:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
Merging happens one level deep. If your file defines "logging": {"level": "DEBUG"}, you keep the default directory, filename, max_size and backup_count and only override level. The same applies to dj_local_conf and SCHEMATA.
Keys with no default — Channels, server.*, video_source_path, video_target_path — are simply absent unless you define them, and code that needs them supplies its own fallback.
Precedence Order¶
For a normal ethopy run, a setting is resolved like this — first match wins:
- Command-line flag, where one exists for that setting (
--log-level,--log-console) - The active configuration file — the
-c/--configfile if given, otherwise~/.ethopy/local_conf.json - Built-in default for that key
Only one configuration file is ever active; files are never merged with each other.
Plugin directories are the exception — they accumulate rather than override. All three sources are scanned, in this order:
plugin_pathfrom the active configuration file~/.ethopy/ethopy_plugins(the default directory)- Each path in
ETHOPY_PLUGIN_PATH, left to right
When two directories contain a module with the same import name, the one scanned later wins, so ETHOPY_PLUGIN_PATH overrides the default directory, which overrides plugin_path. Core EthoPy modules always win over plugins, regardless of source. Each conflict is logged as a warning naming both files. See the Plugin System guide for details.
Essential Configuration¶
Minimal Setup¶
Here's the minimum configuration needed to get EthoPy running:
1 2 3 4 5 6 7 8 9 10 | |
What each part does:
dj_local_conf: Database connection settings (required)source_path: Where experimental data files are saved on this machinetarget_path: Where backup copies should be saved
Configuration Sections¶
1. Database Settings (Required)¶
1 2 3 4 5 6 7 8 9 10 11 12 | |
Settings explanation:
-
database.host: Database server IP address or hostname- Default:
"127.0.0.1"(localhost - your computer) - Examples:
"192.168.1.100","lab-database.university.edu"
- Default:
-
database.user: MySQL username for database connection- Default:
"root"
- Default:
-
database.password: MySQL password for the specified user- Default:
""(empty string)
- Default:
-
database.port: MySQL server port number- Default:
3306(standard MySQL port) - Note: Only change if your MySQL uses a different port
- Default:
-
database.reconnect: Automatically reconnect if connection is lost- Default:
true
- Default:
-
database.use_tls: Use encrypted TLS connection to database, more details here- Default:
false
- Default:
-
datajoint.loglevel: DataJoint library logging verbosity- Default:
"WARNING" - Options:
"DEBUG","INFO","WARNING","ERROR","CRITICAL"
- Default:
2. File Paths (Required)¶
1 2 3 4 | |
Settings explanation:
-
source_path: Local directory where experimental data files are saved- Default:
"~/EthoPy_Files"(EthoPy_Files folder in your home directory) - Purpose: All recorded data (videos, sensor data, etc.) is stored here during experiments
- Examples:
"/Users/yourname/experiment_data","/home/pi/data"
- Default:
-
target_path: Directory where backup copies of data should be moved after experiments- Default:
"/"(root directory - usually needs to be changed) - Purpose: Automatic backup/archival location for completed experiments
- Examples:
"/mnt/lab_storage"
- Default:
Important: Always use full paths starting from your drive root.
3. Logging Settings (Optional)¶
1 2 3 4 5 6 7 8 9 | |
Settings explanation:
-
level: Minimum log level to record- Default:
"INFO" - Options:
"DEBUG"(most verbose),"INFO","WARNING","ERROR","CRITICAL"(least verbose) - Purpose: Controls how much detail is logged
- Default:
-
directory: Directory where log files are stored- Default:
"~/.ethopy/"(hidden .ethopy folder in your home directory) - Examples:
"/var/log/ethopy","/Users/yourname/logs"
- Default:
-
filename: Name of the main log file- Default:
"ethopy.log" - Note: Backup files will be named
ethopy.log.1,ethopy.log.2, etc.
- Default:
-
max_size: Maximum size of log file before rotation (in bytes)- Default:
31457280(30 MB) - Purpose: Prevents log files from growing too large
- Default:
-
backup_count: Number of old log files to keep- Default:
5 - Purpose: Maintains history while preventing unlimited disk usage
- Default:
4. Hardware Setup (Optional - Raspberry Pi only)¶
If you're using physical hardware (valves, sensors, LEDs), specify GPIO pin connections:
1 2 3 4 5 6 7 | |
Settings explanation:
Channels: Maps hardware types to GPIO pin assignments- Default: Not set (no hardware channels configured)
- Purpose: Tells EthoPy which GPIO pins control which hardware devices
Hardware types:
-
Liquid: Water delivery pumps/valves for reward delivery- Format:
{"port_number": gpio_pin_number} - Example:
{"1": 22, "2": 23}means port 1 uses GPIO pin 22, port 2 uses GPIO pin 23
- Format:
-
Lick: Lick detection sensors for behavioral monitoring- Format:
{"sensor_number": gpio_pin_number} - Example:
{"1": 17, "2": 27}means lick sensor 1 on GPIO pin 17, sensor 2 on GPIO pin 27
- Format:
-
Odor: Odor delivery valves for olfactory experiments- Format:
{"valve_number": gpio_pin_number} - Example:
{"1": 24, "2": 25}means valve 1 on GPIO pin 24, valve 2 on GPIO pin 25
- Format:
Important notes:
- Each GPIO pin number can only be used once across all hardware types
5. Custom Schema Names (Optional)¶
If your database uses custom schema names:
1 2 3 4 5 6 7 8 9 | |
Settings explanation:
SCHEMATA: Maps EthoPy data types to your custom database schema names- Purpose: Allows EthoPy to work with existing databases that use different naming conventions
Schema types and defaults:
-
experiment: Main experimental session data- Default:
"lab_experiments" - Contains: Session info, trial data, animal information
- Default:
-
behavior: Behavioral measurement data- Default:
"lab_behavior" - Contains: Lick detection, movement tracking, response data
- Default:
-
stimulus: Stimulus presentation information- Default:
"lab_stimuli" - Contains: Visual/auditory stimuli parameters, timing
- Default:
-
interface: Hardware interface configurations- Default:
"lab_interface" - Contains: Hardware setup parameters, calibration data
- Default:
-
recording: Data recording metadata- Default:
"lab_recordings" - Contains: File paths, recording parameters, data format info
- Default:
Note: Most users can skip this section - EthoPy will use the default schema names.
6. Plugin Path (Optional)¶
1 2 3 | |
Settings explanation:
plugin_path: Directory where EthoPy plugins are stored- Default:
"~/.ethopy/ethopy_plugins"(plugins folder in your .ethopy directory) - Purpose: Location for custom EthoPy extensions and plugins
- Examples:
"/Users/yourname/my_plugins","/opt/ethopy_plugins"
- Default:
Note: Only needed if you're using custom plugins or want to store them in a different
location. plugin_path is one of three plugin sources — the default
~/.ethopy/ethopy_plugins directory and ETHOPY_PLUGIN_PATH are also scanned. All three
are used together; see Precedence Order.
Common Setup Scenarios¶
Local Database Setup (Most Common)¶
1 2 3 4 5 6 7 8 9 10 | |
Remote Database Setup¶
1 2 3 4 5 6 7 8 9 10 | |
Hardware Experiment Setup¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Troubleshooting¶
Problem: "Cannot connect to database"¶
Solutions:
-
Check your password - Verify the password matches your MySQL password
-
Advanced troubleshooting: For remote databases or lab setups, contact your system administrator or IT support to verify database server status, network connectivity, and firewall settings. Check if MySQL is running
- If
database.hostis127.0.0.1orlocalhost: Runmysql -u root -pon the same machine as EthoPy - If
database.hostis a remote IP (like192.168.1.100): Run the command on that remote database server - The command should ask for your password and connect successfully
- If you get "command not found", MySQL client is not installed
- If you get "connection refused", MySQL server is not running
- If
-
Check the database address - For
127.0.0.1, MySQL must be on your computer -
Check the port number - MySQL usually uses 3306
Problem: "Cannot find data path"¶
Solutions:
-
Check the folder exists - Verify the folder exists in your file system
-
Use full paths - Use
/Users/yourname/data/notdata/ -
Check permissions - Ensure you can read and write to the folder
-
Create the folder - Create the folder if it doesn't exist
Problem: "Hardware not responding"¶
Solutions:
-
Check physical connections - Verify all wires are properly connected
-
Check pin numbers - Ensure pin numbers match your hardware setup
-
Check for conflicts - Make sure no pin number is used twice
-
Test with simple LED - Verify basic GPIO functionality
Problem: "Configuration file not found"¶
Solutions:
-
Check file location - Ensure
local_conf.jsonis in~/.ethopy/, or pass your file explicitly withethopy -c /path/to/conf.json -
Check JSON format - Verify proper JSON syntax (no missing commas/brackets). A file that fails to parse is logged as an error and EthoPy falls back to the built-in defaults, which usually shows up as a failed connection to
127.0.0.1 -
Confirm what was loaded - Run
python -c "import ethopy; print(ethopy.local_conf)"to print the active file path and every resolved setting -
Start simple - Copy one of the examples from this guide
Security Best Practices¶
- Never share your config file - It contains database passwords
- Use strong passwords - Protect your database access
- Keep backups - Save a copy of your working configuration
- Use full paths - Avoid relative paths that might break
Local vs Database Settings¶
Store in local_conf.json:
- Database connection details
- File paths specific to this machine
- Hardware GPIO pin assignments
- Logging preferences
- Machine-specific settings
Store in database:
- Experimental parameters
- Trial configurations
- Animal information
- Session data
- Results and measurements
This separation keeps your experiments portable while maintaining machine-specific configurations.