Skip to main content

A simple version-tracking tool for research code development.

Project description

pydift

pydift is a simple version-tracking tool for research code development. It allows you to track changes in your code, generate diffs, and even reconstruct code at specific points in time. Additionally, it can summarize diffs using various language models.

pydift TUI

Current version: 0.1.2

Features

  • Track changes in your Python scripts.
  • Generate diffs between code runs.
  • Summarize diffs using language models.
  • Reconstruct code at specific points in time.
  • Interactive Text User Interface (TUI) for managing diffs and configurations.

Installation

pip install pydift

Usage

Command Line Interface (CLI)

You can use pydift from the command line to track and run your scripts. Here are some examples:

# Track and run a script
pydift script.py
pydift -p script.py
pydift --path script.py

# Track and run a script, and generate a summary of the diff
pydift -s script.py
pydift --summary script.py

# Track all files in the current directory
pydift -w script.py
pydift --wide script.py

# Track all files in the current directory and subdirectories
pydift -r script.py
pydift --recursive script.py

# Launch the pydift TUI
pydift
pydift -t
pydift --tui
pydift path/to/folder

Text User Interface (TUI)

pydift also provides an interactive TUI for managing diffs and configurations. To launch the TUI, run:

pydift --tui
pydift -t

In the TUI, you can:

  • Scroll between diffs of code runs.
  • Select a diff to view or reconstruct the code at that point in time.
  • Configure pydift settings such as the language model, summary generation, and file tracking options.

Configuration

pydift uses a configuration file located at ~/.pydift/pydift_conf.yaml. The default configuration is:

model: "Meta Llama 3.3"
summary: False
wide: False
recursive: False

You can modify these settings directly in the configuration file or through the TUI.

Adding models

By default, pydift is configured with the following models:

  • OpenAI GPT-4o
  • Meta Llama 3.3
  • Google Gemini 2.0 Flash (Exp)

You can add new models to be used by pydift (and then configure appropriately through the TUI), by adding the details of the cURL request to model_conf.yaml (in ~/.pydift). For example,

OpenAI GPT-4o:
    url: "https://api.openai.com/v1/chat/completions"
    headers:
      Content-Type: "application/json"
      Authorization:  "Bearer $API_KEY"
    data:
      model: "gpt-4o"
      messages:
        - role: "user"
          content: none
      max_completion_tokens: 256
      temperature: 0.7
    api_key_env: "OPENAI_API_KEY"
    api_key_path: "headers.Authorization"
    response_path: "choices.0.message.content"
    input_path: "messages.0.content"

Note the following sections:

  • The name of the entry (e.g OpenAI GPT-4o) will appear in the TUI selection screen.
  • The URL is the target of the API call.
  • The headers (typically the same for all models)
  • The data (this differs substantially between models)
  • api_key_path: This indicates in which part of the (entire) request JSON the API key will be inserted (indicated by the placeholder $API_KEY)
  • api_key_env: The name of the environment variable holding the API key.
  • api_key: alternatively, possible to directly give the api_key in the yaml (will be superceded by api_key_env)
  • response_path: Given a successful call to the model's API, assuming the response returns a JSON, this indicates the list of keys, to be accessed in succession, to get the actual text output of the model.
  • input_path: This indicates in which part of the data portion of the request JSON, the prompt will be inserted (in the above example, in data["messages"][0]["content"])

Example

Here is an example of how to use pydift:

  1. Create a Python script example.py:
print("Hello, world!")
  1. Track the script using pydift:
pydift example.py
  1. Modify the script to print a different message:
print("Goodbye, world!")
  1. Track the script again:
pydift example.py
  1. Launch the pydift TUI:
pydift --tui

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

pydift-0.1.2.tar.gz (360.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydift-0.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file pydift-0.1.2.tar.gz.

File metadata

  • Download URL: pydift-0.1.2.tar.gz
  • Upload date:
  • Size: 360.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pydift-0.1.2.tar.gz
Algorithm Hash digest
SHA256 742a343fe1b1b34919b251a77cc60c1f7afb66309220dff966e48c4217589538
MD5 08cfca20fd7b1506d4897203c6925599
BLAKE2b-256 1797ef61e11ea227a476c503be7c5b6fae6cadb91eb15c5242872c03292da1bf

See more details on using hashes here.

File details

Details for the file pydift-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pydift-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pydift-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fed474ac5201211cc908af2b9b03a11b550af34bf4227d8c6a1350ed5dde035b
MD5 d9fa2efc223f4d77194556d23d04103c
BLAKE2b-256 b65eebf60990d00b744fbc9d472c477b64334282612a135edf509d52d584a0fe

See more details on using hashes here.

Supported by

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