vobject

0.9.9 · active · verified Sun Apr 12

vobject is a pure-Python package for parsing and creating iCalendar and vCard files. It supports Python 3.8 or later for the 1.x series (which is under active development, though 0.9.x is currently the latest stable release), while the 0.9.x series (including 0.9.9) supports Python 2.7 and earlier Python 3 versions. The latest version, 0.9.9, was released in December 2024. The project is actively maintained by the py-vobject organization on GitHub, with recent bug fixes and feature additions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic iCalendar event, add properties including datetime objects, and then serialize it into an iCalendar string. It also shows how to parse a vCard string using `vobject.readOne()` and access its properties. Note that `vobject` automatically adds mandatory components like `UID` and `DTSTAMP` during serialization if they are not explicitly set.

import vobject
import datetime

# Create a new iCalendar object
cal = vobject.iCalendar()

# Add an event component
event = cal.add('vevent')

# Add properties to the event
event.add('summary').value = 'Meeting with AI team'
event.add('dtstart').value = datetime.datetime(2026, 4, 15, 10, 0, 0, tzinfo=datetime.timezone.utc)
event.add('dtend').value = datetime.datetime(2026, 4, 15, 11, 0, 0, tzinfo=datetime.timezone.utc)

# Print the iCalendar object in a human-readable format
print('--- Pretty Print ---')
print(cal.prettyPrint())

# Serialize the iCalendar object to its string representation
# vobject will automatically add missing mandatory properties like UID and DTSTAMP
ical_string = cal.serialize()
print('\n--- Serialized iCalendar ---')
print(ical_string)

# Example of parsing a vCard from a string
vcard_string = """
BEGIN:VCARD
VERSION:3.0
N:Doe;John;;;
FN:John Doe
EMAIL;TYPE=WORK:john.doe@example.com
END:VCARD
"""

try:
    parsed_vcard = vobject.readOne(vcard_string)
    print('\n--- Parsed vCard (FN) ---')
    print(parsed_vcard.fn.value)
except Exception as e:
    print(f"Error parsing vCard: {e}")

view raw JSON →