Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Issues Closed Issues License DOI


Behavython logo

Automated Behavioral Analysis Interface
Currently built to integrate seamlessly with DeepLabCut
Other tools coming soon!

Report Bug · Request Feature


Table of Contents


About

Behavython is an automated, high-throughput behavioral analysis interface. It features a modular architecture that converts raw tracking data (CSV/H5) into structured, biologically relevant behavioral metrics.

It natively supports:

  • Geometry-based paradigms: Open Field, Elevated Plus Maze (EPM)
  • Interaction-based paradigms: Social Recognition, Social Discrimination, Object Discrimination

The software enforces strict scientific reproducibility through automated environment management, robust data validation, and granular metric exports.


Getting Started

Standalone Offline Installer (Windows)

For machines without Conda, Python, or administrative permissions to download packages at runtime, we provide a self-contained offline installer bundling Python 3.10, PyTorch, DeepLabCut 3.0+, and the complete CUDA runtime:

  • Download on Zenodo: DOI
  • Simply download Behavython-Setup-0.9.9rc11.exe, run the setup wizard, and launch Behavython from your Desktop or Start Menu.

Automated Installation (Windows)

For a streamlined setup, we provide a batch script that automates the entire process: creating the Conda environment, installing the required pip dependencies, and configuring the CUDA environment.

How to use the installer:

  1. Download the script: Download behavython_installer.bat
    Right-click the link and select "Save Link As..." to download it as a .bat file
    In the windows explorer dowload prompt make sure to select "Save as type: All Files" and not "Text Documents" to avoid saving it as a .txt file
  2. Run the Installer: Double-click the downloaded file and follow the on-screen instructions.
  3. Detailed Instructions: For a full walkthrough of the automated process, refer to our Installation Guide.

Step-by-Step Installation (Manual)

We recommend using mamba (or conda) to manage isolated Python environments. DeepLabCut 2.3.x (TensorFlow) and DeepLabCut 3.0+ (PyTorch) require distinct CUDA runtimes and package versions, so they should be installed into separate environments.

Option A: TensorFlow Environment (DLC < 3.0)

Use this environment for models trained on TensorFlow or created before DeepLabCut 3.0.

mamba create -n behavython-tf python=3.10
mamba activate behavython-tf
mamba install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
pip install "behavython[tf]"

Option B: PyTorch Environment (DLC 3.0+)

Use this environment for models trained on PyTorch with DeepLabCut 3.0+.

Note: DeepLabCut 3.0+ is incompatible with networks trained in DeepLabCut 2.3.

mamba create -n behavython-torch python=3.10
mamba activate behavython-torch
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126
pip install "behavython[torch]"

DeepLabCut Engine Detection & Backend Validation

Behavython checks backend availability before starting video analysis or assisted labeling:

  • Explicit setting: Reads config.yaml for engine: pytorch (or torch) and engine: tensorflow (or tf).
  • Automatic detection: When engine is omitted (standard for networks trained before DLC 3.0), Behavython inspects the model folder structure: dlc-models-pytorch/ resolves to PyTorch, and dlc-models/ resolves to TensorFlow.
  • Dependency checks: If the required backend (torch or tensorflow/tf_slim) is missing from the active environment, Behavython halts early with MissingBackendError and names the missing packages.

CLI Usage

Behavython ships a headless command-line entry point (behavython-cli) for batch processing without opening the GUI. This is useful for server-side automation or scripted pipelines.

Basic usage:

behavython-cli --config run.json

With overrides:

behavython-cli --config run.json --output /data/results --no-plots

A ready-to-edit config template ships with the package at behavython/config/cli_config.json. Fields:

Field Description Default
experiment_type One of: open_field, elevated_plus_maze, social_recognition, social_discrimination, object_discrimination —
input_folder Folder containing all animal files (CSVs, images, ROI/JSON configs) —
output_folder Destination directory for results —
config_path Global fallback arena JSON (maze experiments only) null
arena_width / arena_height Physical arena dimensions in cm 30
frames_per_second Recording frame rate 30
task_duration Analysis window in seconds 300
trim_amount Seconds to skip at video start 0
crop_video Restrict analysis to [trim, trim + duration] false
animal mouse or rat (sets body-length threshold) mouse
figure_resolution Max plot resolution: 640x480, 1280x720, 1920x1080, 2560x1440 1920x1080
no_plots Skip plot generation false
generate_video Generate annotated output video false

Return codes: 0 = all animals valid, 1 = fatal error, 2 = completed with warnings/invalid animals.


Pretrained Models

Pretrained DeepLabCut networks are published on the GitHub Releases page. The GUI downloads them when an action needs one.

The latest release (models-v2.0) includes:

  • c57_network_2025_minified.zip - Pose tracking of C57BL/6 mice, top view, white arena (TensorFlow).
  • cd1_network_2026.zip - Pose tracking of CD1 mice, top view (PyTorch).
  • roi_network_2026.zip - Cup detection for automatic ROI creation in social recognition (PyTorch).

These networks are trained on the social recognition setups of our lab. On other setups, check the results, or train your own network.

To install by hand, extract each ZIP into a folder with the same name inside .behavython/models/ in your home directory, so that config.yaml sits directly inside it:

  • Windows: C:\Users\<YourUsername>\.behavython\models\roi_network_2026\config.yaml
  • Linux/Mac: ~/.behavython/models/roi_network_2026/config.yaml

Video Pre-processing (Experimental)

⚠️ Note: This is currently an experimental feature available only when running Behavython in debug mode. It can be toggled on demand, but please contact the developers for instructions on how to activate it for now.

Behavython includes a dedicated pipeline for standardizing and cropping raw behavioral videos, ensuring they are optimized for computer vision analysis (DeepLabCut, SLEAP, etc.).

High-Performance Batch Cropping

  • Interactive Designer: Draw crop regions and define rotation angles directly on video previews.
  • Hardware Acceleration: Native support for Nvidia NVENC, enabling processing speeds of up to 800+ FPS.
  • Batch Processing: Define settings once and process entire folders in the background.
  • Non-Destructive: Original videos are preserved; results are saved in a /cropped subfolder.

Video Standardization

Many acquisition systems save videos in legacy formats (like MPEG4 or AVI) that are not "reliably seekable." This can lead to desynced frames during tracking. Behavython's Standardization Tool:

  1. Automatic Detection: Background probing detects problematic codecs or variable frame rates.
  2. Lossless Conversion: Converts videos to a pristine H.264 format with Constant Frame Rate (CFR).
  3. Unlocks GPU Speed: Standardizing moves the decoding workload from the CPU to the GPU, often increasing processing speed by 5x to 10x.

Standard Workflow

  1. Select Folder: Click GET FOLDER to choose the directory where your videos are stored (ideally, this folder should only contain the videos you intend to crop).
  2. Standardize (If Prompted): If the interface detects legacy codecs, click the Standardize Videos (Fix Codecs) button to convert them safely.
  3. Open Cropping Window: Click Open Cropping Window to launch the interactive editor.
  4. Draw Crops & Set Coordinates:
    • Drag with the Left Mouse Button across the frame to draw a crop box.
    • Use the Mouse Wheel to rotate the box (hold Ctrl/Shift to adjust rotation speed).
    • Once the crop is perfect, click Set Coordinates for that video.
    • Note: If all your videos have different positions, you must select each video individually, draw the box, and click "Set Coordinates". If the position is identical across videos, simply use the Apply to checked videos button to propagate your settings.
  5. Video List Color Code: The sidebar list uses colors to track your progress:
    • 🟡 Yellow: Needs attention (Coordinates have not been set).
    • 🟢 Green: Ready (Coordinates are set and saved).
    • ⚪ White: Finished (The video has already been cropped in the /cropped folder).
  6. Save Project: Click Save Project (JSON) to write your coordinates to disk.
  7. Execute: Close the cropping window and click CROP VIDEOS in the main GUI to run the batch process.

Workflow & Configuration

The Pipeline

Video → DeepLabCut → Filtered CSV → Behavython Core Pipeline → Metrics & Parquet

Arena Configuration (Geometry Tasks)

For Open Field and Elevated Plus Maze (EPM) experiments, Behavython requires a .json configuration file defining the spatial geometry. You can extract these coordinates using the ImageJ Point Tool.

  • Open Field: Requires exactly 4 ordered corners (Top-Left, Top-Right, Bottom-Right, Bottom-Left).
  • Elevated Plus Maze: Requires exactly 12 ordered points defining the outer boundaries, arms, and center zone.

Example: Open Field (arena.json) Use the image as reference to order the points correctly. Here, you can copy this example and save as a .json file to use In order, the points should be created in imageJ in this sequence:

  1. top-left
  2. top-right
  3. bottom-right
  4. bottom-left
{
  "experiment_type": "open_field",
  "arena_corners": [
    [126.0, 72.0],
    [637.0, 74.0],
    [633.0, 581.0],
    [128.0, 581.0]
  ]
}

Example: Elevated Plus Maze (arena.json) As with the open field, use the image as reference to order the points correctly. Here, you can copy this example and save as a .json file to use In order, the points should be created in imageJ in this sequence:

  1. Center Top Left
  2. Top Left
  3. Top Right
  4. Center Top Right
  5. Right Top
  6. Right Bottom
  7. Center Bottom Right
  8. Bottom Right
  9. Bottom Left
  10. Center Bottom Left
  11. Left Bottom
  12. Left Top
{
  "experiment_type": "elevated_plus_maze",
  "maze_points": [
    [128, 336],
    [384, 336],
    [384, 32],
    [514, 32],
    [514, 336],
    [900, 336],
    [900, 446],
    [514, 446],
    [514, 1042],
    [384, 1042],
    [384, 446], 
    [128, 446]
  ]
}

Note: Incorrect coordinate ordering will corrupt spatial occupancy metrics.

Geometry Point Ordering Reference
Coordinate ordering reference for Open Field and Elevated Plus Maze.

ROI Configuration (Interaction Tasks)

For interaction paradigms (like Social Recognition or Object Discrimination), Behavython requires Region of Interest (ROI) definitions exported as CSV files. You can generate these using the ImageJ Oval Tool.

ROI Requirements:

  • ImageJ Measurements: Go to Analyze → Set Measurements. You must ensure both Centroid and Bounding Rectangle are checked. The resulting CSV needs the bounding box (BX, BY, Width, Height) and centroid (X, Y) coordinates.
  • File Naming Convention: The exported CSV must contain the original video name, followed by an ROI identifier:
    • Single-Object/Target: video_name_roi.csv
    • Two-Choice Tasks: video_name_roiL.csv and video_name_roiR.csv (Left and Right).
  • File Format: The file must be a standard .csv (Comma Separated Values) file.

Example: Social Recognition/Discrimination (video_name_roi.csv)

 ,Area,X,Y,BX,BY,Width,Height
1,24065,376.500,387.500,289,300,175,175

Automatic ROIs (Social Recognition): The CREATE ROIS button in the DeepLabCut tab, or behavython-cli -f <folder> --create-rois, writes video_name_roi.csv for each video with roi_network_2026. The network finds the top, right, bottom and left points of the cup on 5 frames per video, skipping the first 10%. The median of each point gives the center (X, Y), Width (left-right) and Height (top-bottom). Existing ROI files are never overwritten. Check the images in the roi_check folder, draw the ROIs that are wrong by hand, and read the warnings in the log about frames or videos that disagree. The network is trained on our CD1 and C57 cups only. For other setups, right-click the button (or pass --roi-config) to use your own DLC network with the bodyparts top, right, bottom and left.


Outputs & Metrics

The pipeline outputs data in multiple formats for both statistical aggregation and granular programmatic review.

General Storage

  • analysis_summary.xlsx / .csv: Scalar metrics aggregated per animal.
  • analysis_timeseries.parquet: Highly compressed, frame-by-frame data utilizing Apache Arrow for efficient downstream data science workflows.
  • analysis_log.json: Comprehensive error and warning logs per session.

Task-Specific Metrics

Geometry Experiments (Open Field, EPM):

  • Zone occupancy times and percentages.
  • Transition counts between zones.
  • Discrete spatial_state arrays per frame.

Interaction Experiments (Social/Object):

  • Investigation and approach proportions.
  • Mean inter-bout intervals (seconds).
  • Discrete bout analysis (Collision bouts, approach-only bouts, abortive retreats). These counts, the proportions and the intervals above are computed on approach sequences: each approach is linked to a following collision and retreat within 1 s. A collision with no preceding approach is not counted in them.
  • bouts.xlsx: two long tables for manual analysis, one row per event, all animals stacked, with animal_id and roi_name columns and times in seconds. Also saved as investigation_bouts.parquet and approach_sequences.parquet.
    • investigation_bouts sheet: one row per contiguous run of collision frames (at least 3 frames) in one ROI, regardless of approach or retreat. Columns: bout_id, start_s, end_s, duration_s, start_frame, end_frame. Durations add up to the exploration time, except for runs under 3 frames.
    • approach_sequences sheet: one row per approach sequence, with its outcome (collision, abortive_retreat or approach_only) and the start and end of each stage (approach, collision, retreat). Stages that did not happen are empty.
  • analysis_collisions.parquet: Granular export containing distance to objects, interaction angles, and frame-by-frame flags.

Contributing

Contributions to the codebase and scientific pipelines are welcome.

  • Open an issue to report bugs or suggest features.
  • Submit a pull request for code changes. Ensure modifications align with the project's modular architecture and strict type-hinting standards.

Citation

If you use Behavython in your research, please cite:

@software{passos_moreira_behavython_2026,
  author       = {Passos, Matheus Costa and Carvalho Moreira, João Pedro},
  title        = {Behavython: Automated behavioral analysis software and pipeline for neuroscience},
  year         = {2026},
  publisher    = {Zenodo},
  version      = {0.9.9rc11},
  url          = {https://github.com/mrdrzit/behavython}
}

Metadata is also available in CITATION.cff.


License

This project is distributed under the GNU GPL v3.0 License. See the LICENSE file for more information.


Contact


Acknowledgments


Developed at
Núcleo de Neurociências (NNC)
Universidade Federal de Minas Gerais (UFMG)
Brazil

Metadata

Release files for behavython 0.9.9rc12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for behavython 0.9.9rc12
File Size Uploaded Provenance Actions
behavython-0.9.9rc12.tar.gz 842.2 kB Without provenance Details for behavython-0.9.9rc12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for behavython 0.9.9rc12
File Interpreter ABI Platform Actions
behavython-0.9.9rc12-py3-none-any.whl Python 3 none any Details for behavython-0.9.9rc12-py3-none-any.whl

Total release size: 1.7 MB

Release files / behavython-0.9.9rc12.tar.gz

Download URL behavython-0.9.9rc12.tar.gz
Size 842.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d93a1a42fd342838534a464c31173f57d3d9f1e6456a846b68d7a5f0b28f56ca
BLAKE2b-256 checksum
How to use checksums
e150b9155154fe8faf582828551539c5f7491b325662c8fd79875f304507b39f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21

Release files / behavython-0.9.9rc12-py3-none-any.whl

Download URL behavython-0.9.9rc12-py3-none-any.whl
Size 847.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eaf5858268ef8339ffc06651b8686ae14181154a6a919386fa0453f665b2902c
BLAKE2b-256 checksum
How to use checksums
a0de5ac21a57453eb6e476e1a986331023e6fb3f0934878480e5e15b6bfd628e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21

Security for behavython 0.9.9rc12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page