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

A 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.0.tar.gz (12.5 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.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_cozi_client-1.1.0.tar.gz
  • Upload date:
  • Size: 12.5 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.0.tar.gz
Algorithm Hash digest
SHA256 807f835dd57bdd6059a0a7871d6c66bff9089635ec82c2e17dc45da7c88733f5
MD5 12ac2b03c3425ffe73817e60f6244674
BLAKE2b-256 b97d03cb35f90953b10b705c7c089651b42f87fa483dee9c193422a7e87981f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_cozi_client-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0a2e310319846a7e1d8cff8811a52ac176bcb825c4ba52c841d08ba16dbd9ad
MD5 22f95c9604b82394a7c849899ba21c8f
BLAKE2b-256 5b437e1ce8f2e136beb5a7c2eaf1b5ccc546b8ccd33b6e72f121521a30bbd933

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