Skip to main content

A Python client for CalDAV task servers, with a CLI.

Project description

PyPI version

(Full documentation available at caldavtasksapi.readthedocs.io)

CalDAV-Tasks-API

A Python library and command-line interface (CLI) for interacting with CalDAV task lists (VTODOs). This project provides tools to connect to a CalDAV server, fetch task lists and tasks, create new tasks, and delete existing ones.

Table of Contents

Motivation and Purpose

This library was developed as a foundational component for integrating CalDAV task management with more advanced systems. The primary goal is to serve as a backbone for:

  1. Synchronizing tasks from applications like the excellent Tasks.org Android app.
  2. Enabling features such as smart task prioritization using ELO ranking, envisioned to work with a Litoy-like setup.
  3. Making useful python objects with handy methods to manipulate caldav's tasks.
  4. Making a CLI interface to manipulate tasks (secondary goal).

By providing a robust Python interface to CalDAV tasks, this project aims to bridge the gap between standard task management and custom, intelligent task processing workflows. The library is intentionally designed to be minimal, with few external dependencies, to ensure it is lightweight and easy to integrate.

Compatibility

The API has been primarily tested with Nextcloud Tasks. However, it is designed to be compatible with any CalDAV server that supports VTODO components.

Testers and feedback for other CalDAV server implementations (e.g., Baïkal, Radicale, Synology Calendar) are highly welcome!

Features

  • Connect to CalDAV servers with optional Nextcloud-specific URL adjustments.
  • Load task lists (calendars supporting VTODOs).
  • Load tasks from specified lists, parsing standard iCalendar properties.
  • Preserve and provide access to custom X- properties.
  • Create, update, and delete tasks (VTODOs) on the server.
  • Access parent and child task relationships (TaskData.parent_task and TaskData.child_tasks).
  • Read-only mode for applications that need to prevent modifications.
  • CLI with multiple commands: show summaries, list tasks, add tasks, and list available task lists.
  • JSON output support for integration with other tools.
  • Environment variable support for credentials and default settings.

Installation

The CalDAV Tasks API can be installed directly from PyPI:

uv pip install caldav-tasks-api

Alternatively, you can install from source:

  1. Clone the repository:
    git clone <repository_url>
    cd caldav-tasks-api
    
  2. Install dependencies (ensure you have python>=3.8):
    # Install the package and all dependencies:
    uv pip install .
    
    # For development with editable install:
    uv pip install -e .
    
    # For development with additional dev dependencies:
    uv pip install -e ".[dev]"
    

Configuration

The library supports configuration via environment variables:

  • CALDAV_TASKS_API_URL: CalDAV server URL
  • CALDAV_TASKS_API_USERNAME: CalDAV username
  • CALDAV_TASKS_API_PASSWORD: CalDAV password
  • CALDAV_TASKS_API_DEFAULT_LIST_UID: Default task list UID for operations
  • CALDAV_TASKS_API_DEFAULT_PRIORITY: Default priority to use when creating tasks
  • CALDAV_TASKS_API_LOG_LEVEL: Default log level, by default WARNING

Usage

Command Line Interface

The package provides several CLI commands:

# Show summary of all task lists and tasks
python -m caldav_tasks_api show-summary

# Show summary with JSON output
python -m caldav_tasks_api show-summary --json

# List available task lists
python -m caldav_tasks_api list-lists

# List latest tasks from a specific list
python -m caldav_tasks_api list-latest-tasks --list-uid <list-uid>

# Dump all the tasks of a list as VTODO format
python -m caldav_tasks_api dump-all-tasks --list-uid <list-uid>

# Add a new task
python -m caldav_tasks_api add-task --list-uid <list-uid> --summary "My new task"

# Add a task with additional properties
python -m caldav_tasks_api add-task \
  --list-uid <list-uid> \
  --summary "Important task" \
  --description "Task description" \
  --priority 5 \
  --due-date 20240315 \
  --tag urgent --tag work

All commands support --help for detailed options.

Python API

from caldav_tasks_api import TasksAPI
from caldav_tasks_api.utils.data import TaskData

# Initialize API (credentials from environment or parameters)
api = TasksAPI(
    url="https://your-server.com/remote.php/dav/",
    username="your-username", 
    password="your-password"
)

# Load all task lists and tasks
api.load_remote_data()

# Access task lists
for task_list in api.task_lists:
    print(f"List: {task_list.name} ({len(task_list.tasks)} tasks)")
    
    for task in task_list.tasks:
        print(f"  - {task.summary}")

# Create a new task
new_task = TaskData(
    summary="My new task",
    list_uid="your-list-uid",
    description="Task description",
    priority=5
)
created_task = api.add_task(new_task)

# Update a task
task = api.get_task_by_global_uid("task-uid")
if task:
    task.summary = "Updated task title"
    api.update_task(task)

Contributing

Contributions are welcome! If you'd like to contribute, please feel free to:

  1. Open an issue to discuss a bug, feature request, or an idea.
  2. Fork the repository and submit a pull request with your changes.

Please ensure your code follows the existing style and includes tests where appropriate.

Acknowledgements

This project was developed with the assistance of aider.chat, an AI pair programmer.

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

caldav_tasks_api-1.5.1.tar.gz (47.2 kB view details)

Uploaded Source

Built Distribution

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

caldav_tasks_api-1.5.1-py3-none-any.whl (40.0 kB view details)

Uploaded Python 3

File details

Details for the file caldav_tasks_api-1.5.1.tar.gz.

File metadata

  • Download URL: caldav_tasks_api-1.5.1.tar.gz
  • Upload date:
  • Size: 47.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for caldav_tasks_api-1.5.1.tar.gz
Algorithm Hash digest
SHA256 b029ec1aed1eea3bf30cfacf5e0d5a740f5d24d0aca42f1c12b5dac04836e020
MD5 6d2c41cba8694e708a9c34fd1bee3b5d
BLAKE2b-256 fec34d44f93c1fc302016b5cef85d2af1014497cd43b1e36aa62409efcddf423

See more details on using hashes here.

File details

Details for the file caldav_tasks_api-1.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for caldav_tasks_api-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6b98addcaecccdffbcafdb8e690a91dbd257ec9dd26c01121dde518af885a64
MD5 3f23d60473a5e0fe3d02c8360d220951
BLAKE2b-256 648256aad2faf4145c9968fee191a044417cd09da1a6c69cd5a38eefc7a8d2c1

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