Skip to main content

Async Python client for the Cozi Family Organizer API with full type safety and comprehensive error handling

Project description

py-cozi-client

An unofficial Python client for the Cozi Family Organizer API that provides a robust and type-safe interface to the Cozi service.

Features

  • Async/await support - Built with aiohttp for efficient async operations
  • Type safety - Full type hints and data classes for all API interactions
  • Comprehensive API coverage - Support for lists, calendar, and account management
  • Error handling - Custom exception classes for different error scenarios
  • Rate limiting - Built-in rate limit handling and retry logic
  • Authentication - Secure credential management and session handling

Installation

pip install py-cozi-client

For development:

pip install py-cozi-client[dev]

Quick Start

import asyncio
from cozi_client import CoziClient
from models import ListType, ItemStatus

async def main():
    async with CoziClient() as client:
        # Authenticate
        await client.authenticate("your_username", "your_password")
        
        # Create a shopping list
        shopping_list = await client.create_list("Groceries", ListType.SHOPPING)
        
        # Add items to the list
        await client.add_item(shopping_list.id, "Milk")
        await client.add_item(shopping_list.id, "Bread")
        
        # Get all lists
        lists = await client.get_lists()
        for lst in lists:
            print(f"List: {lst.name} ({lst.type.value})")

asyncio.run(main())

API Reference

CoziClient

The main client class for interacting with the Cozi API.

Authentication

await client.authenticate(username: str, password: str)
await client.logout()

List Management

# Create lists
await client.create_list(name: str, list_type: ListType)

# Get lists
await client.get_lists() -> List[CoziList]
await client.get_list(list_id: str) -> CoziList

# Delete lists
await client.delete_list(list_id: str)

Item Management

# Add items
await client.add_item(list_id: str, text: str, assignee_id: Optional[str] = None)

# Update items
await client.update_item(list_id: str, item_id: str, text: Optional[str] = None, 
                        status: Optional[ItemStatus] = None)

# Remove items
await client.remove_item(list_id: str, item_id: str)

# Get items
await client.get_items(list_id: str) -> List[CoziItem]

Calendar Operations

# Get appointments
await client.get_appointments(start_date: date, end_date: date) -> List[CoziAppointment]

# Create appointments
await client.create_appointment(subject: str, start_time: datetime, 
                               end_time: datetime, location: Optional[str] = None)

Account Management

# Get family members
await client.get_family_members() -> List[CoziPerson]

# Get account information
await client.get_account_info()

Data Models

CoziList

@dataclass
class CoziList:
    id: str
    name: str
    type: ListType
    created_date: datetime
    items: List[CoziItem]

CoziItem

@dataclass
class CoziItem:
    id: str
    text: str
    status: ItemStatus
    assignee_id: Optional[str]
    created_date: datetime

CoziAppointment

@dataclass
class CoziAppointment:
    id: str
    subject: str
    start_time: datetime
    end_time: datetime
    location: Optional[str]
    attendees: List[str]

Enums

class ListType(Enum):
    SHOPPING = "shopping"
    TODO = "todo"

class ItemStatus(Enum):
    COMPLETE = "complete"
    INCOMPLETE = "incomplete"

Exceptions

  • CoziException - Base exception class
  • AuthenticationError - Authentication failures
  • ValidationError - Request validation errors
  • RateLimitError - API rate limit exceeded
  • APIError - General API errors
  • NetworkError - Network connectivity issues
  • ResourceNotFoundError - Resource not found (404)

Development

Setup

git clone <repository-url>
cd py-cozi-client
pip install -e .[dev]

Examples

See the test files for comprehensive usage examples:

  • test_list_operations.py - List and item management
  • test_calendar_operations.py - Calendar and appointment management

Requirements

  • Python 3.7+
  • aiohttp 3.9.2+

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Author

Matthew Jucius

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

py_cozi_client-1.1.2.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

py_cozi_client-1.1.2-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file py_cozi_client-1.1.2.tar.gz.

File metadata

  • Download URL: py_cozi_client-1.1.2.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py_cozi_client-1.1.2.tar.gz
Algorithm Hash digest
SHA256 f285b58734ae7d6951f3613bd4871422034ea6dc6b9ec133289adfc8190a8033
MD5 89ba60a76565cf1cb4d8018baa0d9be6
BLAKE2b-256 4d3bc2438162c90ae89ca810ff50d12ec07d809299aa796890c6145e916e41f7

See more details on using hashes here.

File details

Details for the file py_cozi_client-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: py_cozi_client-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py_cozi_client-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7971d3b57e5e142c638765f1a83161eb0c75b9111545f5d823152c72595960a9
MD5 46a9ef84ea4c7db9ef13c85344c5963b
BLAKE2b-256 a87b4f3454a2b228a9d735da38f7cdaa757264084d4b3a960599c622347a4408

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