Library API Reference
Complete API documentation for the vCon library - a Python implementation of the vCon 0.3.0 specification for Virtual Conversation objects.
vCon Library API Reference
Complete API documentation for the vCon library - a Python implementation of the latest vCon specification for Virtual Conversation objects.
Overview
The vCon library provides a complete Python implementation of the latest vCon specification for representing virtual conversations. It supports all features including parties, dialogs, attachments, analysis, digital signatures, extensibility, and advanced extensions for lawful basis management and standardized transcription formats.
Installation
pip install vconFor image processing support:
pip install vcon[image]Core Classes
Vcon Class
The main class for working with vCon objects.
Constructor
Vcon(vcon_dict: Dict[str, Any] = None, property_handling: str = "default")Parameters:
vcon_dict(Dict[str, Any], optional): Dictionary representing a vCon. Defaults to empty dict.property_handling(str): How to handle non-standard properties:"default": Keep non-standard properties (default)"strict": Remove non-standard properties"meta": Move non-standard properties to meta object
Class Methods
build_new() -> Vcon
Create a new vCon object with default values.
build_from_json(json_str: str, property_handling: str = "default") -> Vcon
Create a vCon object from JSON string.
load(file_path_or_url: str, property_handling: str = "default") -> Vcon
Load a vCon from file or URL.
load_from_file(file_path: str, property_handling: str = "default") -> Vcon
Load a vCon from a local file.
load_from_url(url: str, property_handling: str = "default") -> Vcon
Load a vCon from a URL.
validate_file(file_path: str) -> Tuple[bool, List[str]]
Validate a vCon file.
validate_json(json_str: str) -> Tuple[bool, List[str]]
Validate a vCon JSON string.
generate_key_pair() -> Tuple[rsa.RSAPrivateKey, rsa.RSAPublicKey]
Generate RSA key pair for digital signatures.
uuid8_domain_name(domain_name: str) -> str
Generate UUID8 with domain name.
uuid8_time(custom_c_62_bits: int) -> str
Generate UUID8 with custom time bits.
Instance Methods
Party Management
add_party(party: Party) -> None
Add a party to the vCon.
find_party_index(by: str, val: str) -> Optional[int]
Find party index by field value.
Dialog Management
add_dialog(dialog: Dialog) -> None
Add a dialog to the vCon.
find_dialog(by: str, val: str) -> Optional[Dialog]
Find dialog by field value.
find_dialogs_by_type(type: str) -> List[Dict[str, Any]]
Find all dialogs of a specific type.
add_transfer_dialog(start: Union[datetime, str], transfer_data: Dict[str, Any], parties: List[int]) -> None
Add a transfer dialog.
add_incomplete_dialog(start: Union[datetime, str], disposition: str, parties: List[int]) -> None
Add an incomplete dialog.
Attachment Management
add_attachment(type: str, body: Any, encoding: str = "none") -> Attachment
Add an attachment to the vCon.
add_image(image_path: str, type: str = "image") -> Attachment
Add an image attachment from file.
find_attachment_by_type(type: str) -> Optional[Dict[str, Any]]
Find attachment by type.
Analysis Management
add_analysis(type: str, dialog: Union[int, List[int]], vendor: str, body: Any, encoding: str = "none") -> None
Add analysis data to the vCon.
find_analysis_by_type(type: str) -> Optional[Dict[str, Any]]
Find analysis by type.
Tag Management
add_tag(tag_name: str, tag_value: str) -> None
Add a tag to the vCon.
get_tag(tag_name: str) -> Optional[str]
Get a tag value.
Extension Management
add_extension(extension: str) -> None
Add an extension to the vCon.
get_extensions() -> List[str]
Get list of extensions.
remove_extension(extension: str) -> None
Remove an extension.
add_must_support(extension: str) -> None
Add a must-support extension.
get_must_support() -> List[str]
Get list of must-support extensions.
remove_must_support(extension: str) -> None
Remove a must-support extension.
Extension-Specific Methods
add_lawful_basis_attachment(lawful_basis: str, expiration: str, purpose_grants: list, party_index: Optional[int] = None, dialog_index: Optional[int] = None, **kwargs) -> None
Add a lawful basis attachment to the vCon.
add_wtf_transcription_attachment(transcript: Dict[str, Any], segments: List[Dict[str, Any]], metadata: Dict[str, Any], party_index: Optional[int] = None, dialog_index: Optional[int] = None, **kwargs) -> None
Add a WTF transcription attachment to the vCon.
find_lawful_basis_attachments(party_index: Optional[int] = None) -> List[Dict[str, Any]]
Find lawful basis attachments in the vCon.
find_wtf_attachments(party_index: Optional[int] = None) -> List[Dict[str, Any]]
Find WTF transcription attachments in the vCon.
check_lawful_basis_permission(purpose: str, party_index: Optional[int] = None) -> bool
Check if permission is granted for a specific purpose.
validate_extensions() -> Dict[str, Any]
Validate all extensions in the vCon.
process_extensions() -> Dict[str, Any]
Process all extensions in the vCon.
Security
sign(private_key: Union[rsa.RSAPrivateKey, bytes]) -> None
Sign the vCon with a private key.
verify(public_key: Union[rsa.RSAPublicKey, bytes]) -> bool
Verify the vCon signature.
Validation
is_valid() -> Tuple[bool, List[str]]
Validate the vCon object.
Serialization
to_json() -> str
Convert vCon to JSON string.
to_dict() -> Dict[str, Any]
Convert vCon to dictionary.
dumps() -> str
Alias for to_json().
save_to_file(file_path: str) -> None
Save vCon to file.
HTTP Operations
post_to_url(url: str, headers: Optional[Dict[str, str]] = None) -> requests.Response
Post vCon to URL.
Timestamp Management
set_created_at(created_at: Union[str, datetime]) -> None
Set the creation timestamp.
set_updated_at(timestamp: Union[str, datetime]) -> None
Set the update timestamp.
Properties
uuid -> str
Get the vCon UUID.
vcon -> Optional[str]
Get the vCon version (optional field).
subject -> Optional[str]
Get the vCon subject.
created_at
Get the creation timestamp.
updated_at
Get the update timestamp.
redacted
Get the redacted flag.
appended
Get the appended flag.
group
Get the group information.
meta
Get the metadata.
parties -> List[Party]
Get list of parties.
dialog -> List[Dict[str, Any]]
Get list of dialogs.
attachments -> List[Dict[str, Any]]
Get list of attachments.
analysis -> List[Dict[str, Any]]
Get list of analysis data.
tags -> Optional[Dict[str, Any]]
Get all tags.
Party Class
Represents a participant in a vCon conversation.
Constructor
Parameters:
tel(str, optional): Telephone numberstir(str, optional): STIR identifiermailto(str, optional): Email addressname(str, optional): Display namevalidation(str, optional): Validation informationgmlpos(str, optional): GML position coordinatescivicaddress(CivicAddress, optional): Civic address informationuuid(str, optional): Unique identifierrole(str, optional): Role in conversation (e.g., "caller", "agent")contact_list(str, optional): Contact list referencemeta(dict, optional): Additional metadatasip(str, optional): SIP URI for VoIP communicationdid(str, optional): Decentralized IdentifierjCard(dict, optional): vCard format contact informationtimezone(str, optional): Party's timezone
Methods
to_dict() -> Dict[str, Any]
Convert Party to dictionary.
Dialog Class
Represents a dialog segment in a vCon conversation.
Constructor
Parameters:
type(str): Dialog type ("text", "recording", "transfer", "incomplete", "audio", "video")start(Union[datetime, str]): Start timeparties(List[int]): List of party indicesoriginator(int, optional): Originator party indexmimetype(str, optional): MIME type of contentfilename(str, optional): Filenamebody(str, optional): Content bodyencoding(str, optional): Content encodingurl(str, optional): External URLalg(str, optional): Signature algorithmsignature(str, optional): Content signaturedisposition(str, optional): Disposition for incomplete dialogsparty_history(List[PartyHistory], optional): Party event historytransferee(int, optional): Transferee party indextransferor(int, optional): Transferor party indextransfer_target(int, optional): Transfer target party indexoriginal(int, optional): Original dialog indexconsultation(int, optional): Consultation dialog indextarget_dialog(int, optional): Target dialog indexcampaign(str, optional): Campaign identifierinteraction(str, optional): Interaction identifierskill(str, optional): Skill identifierduration(float, optional): Dialog durationmeta(dict, optional): Additional metadatametadata(Dict[str, Any], optional): Structured metadatatransfer(Dict[str, Any], optional): Transfer-specific informationsignaling(Dict[str, Any], optional): Signaling informationresolution(str, optional): Video resolution (e.g., "1920x1080")frame_rate(float, optional): Video frame ratecodec(str, optional): Video codecbitrate(int, optional): Video bitratethumbnail(str, optional): Base64-encoded thumbnailsession_id(str, optional): Session identifiercontent_hash(str, optional): Content hash for external filesapplication(str, optional): Application identifiermessage_id(str, optional): Message identifier
Methods
to_dict() -> Dict[str, Any]
Convert Dialog to dictionary.
add_external_data(url: str, filename: str, mimetype: str) -> None
Add external data to dialog.
add_inline_data(body: str, filename: str, mimetype: str) -> None
Add inline data to dialog.
is_external_data() -> bool
Check if dialog has external data.
is_inline_data() -> bool
Check if dialog has inline data.
is_text() -> bool
Check if dialog is text type.
is_recording() -> bool
Check if dialog is recording type.
is_transfer() -> bool
Check if dialog is transfer type.
is_incomplete() -> bool
Check if dialog is incomplete type.
is_audio() -> bool
Check if dialog has audio content.
is_video(content_type: Optional[str] = None) -> bool
Check if dialog has video content.
is_email() -> bool
Check if dialog is email type.
is_image() -> bool
Check if dialog has image content.
is_pdf() -> bool
Check if dialog has PDF content.
add_video_data(video_data, filename: Optional[str] = None, mimetype: Optional[str] = None, inline: bool = True, metadata: Optional[dict] = None) -> None
Add video data to dialog.
extract_video_metadata(video_path: Optional[str] = None) -> dict
Extract video metadata using FFmpeg.
generate_thumbnail(timestamp: float = 0.0, width: int = 320, height: int = 240, quality: int = 90) -> bytes
Generate video thumbnail.
add_streaming_video_reference(reference_id: str, mimetype: str, metadata: Optional[dict] = None) -> None
Add streaming video reference.
add_video_with_optimal_storage(video_data, filename: str, mimetype: Optional[str] = None, size_threshold_mb: int = 10) -> None
Add video with optimal storage method.
transcode_video(target_format: str, codec: Optional[str] = None, bit_rate: Optional[int] = None, width: Optional[int] = None, height: Optional[int] = None) -> None
Transcode video to different format.
add_image_data(image_path: str, mimetype: Optional[str] = None) -> None
Add image data from file.
extract_image_metadata(image_data: bytes, mimetype: str) -> None
Extract image metadata.
generate_thumbnail(max_size: Tuple[int, int] = (200, 200)) -> Optional[str]
Generate image thumbnail.
is_external_data_changed() -> bool
Check if external data has changed.
to_inline_data() -> None
Convert external data to inline data.
set_session_id(session_id: str) -> None
Set session identifier.
get_session_id() -> Optional[str]
Get session identifier.
set_content_hash(content_hash: str) -> None
Set content hash.
get_content_hash() -> Optional[str]
Get content hash.
calculate_content_hash(algorithm: str = "sha256") -> str
Calculate content hash.
verify_content_hash(expected_hash: str, algorithm: str = "sha256") -> bool
Verify content hash.
CivicAddress Class
Represents civic address information according to GEOPRIV specification.
Constructor
Parameters:
country(str, optional): Country code (ISO 3166-1 alpha-2)a1(str, optional): Administrative area 1 (state/province)a2(str, optional): Administrative area 2 (county/municipality)a3(str, optional): Administrative area 3 (city/town)a4(str, optional): Administrative area 4 (neighborhood/district)a5(str, optional): Administrative area 5 (postal code)a6(str, optional): Administrative area 6 (building/floor)prd(str, optional): Premier (department/suite number)pod(str, optional): Post office box identifiersts(str, optional): Street namehno(str, optional): House numberhns(str, optional): House namelmk(str, optional): Landmark nameloc(str, optional): Location nameflr(str, optional): Floornam(str, optional): Name of locationpc(str, optional): Postal code
Methods
to_dict() -> Dict[str, Optional[str]]
Convert CivicAddress to dictionary.
PartyHistory Class
Represents party history events in a vCon dialog.
Constructor
Parameters:
party(int): Index of the partyevent(str): Event type ("join", "drop", "hold", "unhold", "mute", "unmute")time(datetime): Time of the event
Methods
to_dict() -> Dict[str, Any]
Convert PartyHistory to dictionary.
Attachment Class
Represents an attachment in a vCon.
Constructor
Parameters:
type(str): Type of attachmentbody(Any): Content of attachmentencoding(str): Encoding format ("base64", "base64url", "none")
Methods
to_dict() -> Dict[str, Any]
Convert Attachment to dictionary.
from_image(image_path: str, type: str = "image") -> 'Attachment'
Create attachment from image file.
Extensions
The vCon library includes a comprehensive extension framework that allows for standardized implementation of additional functionality. Two major extensions are currently implemented: the Lawful Basis extension for privacy compliance and the WTF (World Transcription Format) extension for standardized transcription data.
Extension Framework
The extension framework provides a standardized way to add new functionality to vCon objects while maintaining compatibility and validation.
Core Extension Classes
ExtensionType
Enumeration of extension types:
COMPATIBLE: Safe to ignore, no breaking changesINCOMPATIBLE: Must be supported, breaking changesEXPERIMENTAL: Development/testing only
ExtensionValidator
Abstract base class for extension validation logic.
ExtensionProcessor
Abstract base class for extension processing logic.
ExtensionRegistry
Central registry for managing extensions.
Lawful Basis Extension
The Lawful Basis extension provides comprehensive support for privacy compliance and consent management according to GDPR and other privacy regulations.
Key Features
Multiple Lawful Basis Types: consent, contract, legal_obligation, vital_interests, public_task, legitimate_interests
Purpose-Specific Permissions: Granular permission grants with conditions
Cryptographic Proof Mechanisms: Verbal confirmation, signed documents, cryptographic signatures, external systems
Temporal Validity: Expiration dates and status intervals
Content Integrity: Hash validation and canonicalization
External Registry Integration: SCITT (Supply Chain Integrity, Transparency, and Trust) support
Core Classes
LawfulBasisAttachment
Main class representing a lawful basis attachment.
PurposeGrant
Represents a purpose-specific permission grant.
ContentHash
Represents content integrity information.
ProofMechanism
Represents a proof mechanism for lawful basis.
Validation and Processing
LawfulBasisValidator
Validates lawful basis attachments and extension usage.
LawfulBasisProcessor
Processes lawful basis attachments and evaluates permissions.
Registry Integration
SCITTRegistryClient
Client for SCITT (Supply Chain Integrity, Transparency, and Trust) registries.
WTF Extension
The WTF (World Transcription Format) extension provides standardized representation of speech-to-text transcription data from multiple providers.
Key Features
Multi-Provider Support: Whisper, Deepgram, AssemblyAI, Google, Amazon, Azure, and more
Standardized Format: Hierarchical structure with transcripts, segments, words, and speakers
Quality Metrics: Audio quality assessment and confidence scoring
Export Capabilities: SRT and WebVTT subtitle formats
Provider Adapters: Automatic conversion from provider-specific formats
Analysis Tools: Keyword extraction, confidence analysis, and transcription comparison
Core Classes
WTFAttachment
Main class representing a WTF transcription attachment.
Transcript
Represents high-level transcript information.
Segment
Represents a logical chunk of transcribed content.
Word
Represents a single word in the transcription.
Speaker
Represents speaker information for diarization.
Quality
Represents quality metrics for the transcription.
Provider Adapters
WhisperAdapter
Converts Whisper transcription data to WTF format.
DeepgramAdapter
Converts Deepgram transcription data to WTF format.
AssemblyAIAdapter
Converts AssemblyAI transcription data to WTF format.
Export Capabilities
SRT Export
Export transcription to SRT subtitle format.
WebVTT Export
Export transcription to WebVTT format.
Analysis Tools
Keyword Extraction
Extract keywords from high-confidence words.
Low Confidence Detection
Find segments with confidence below threshold.
Speaking Time Calculation
Calculate speaking time for each speaker.
Validation and Processing
WTFValidator
Validates WTF transcription attachments.
WTFProcessor
Processes WTF transcription attachments and provides analysis.
Constants
Property Handling Modes
Dialog Types
Disposition Values
Party History Events
Attachment Encodings
Supported MIME Types
Extension Types
Lawful Basis Types
Proof Types
Hash Algorithms
Canonicalization Methods
WTF Provider Adapters
Examples
Basic vCon Creation
Loading and Validation
Digital Signatures
Extensions and Must-Support
Analysis and Attachments
Video Content
Civic Address
Party History
HTTP Operations
Property Handling
Lawful Basis Extension
WTF Extension
Extension Validation and Processing
Provider Data Conversion
Complete Extension Workflow
This API reference covers all the main functionality of the vCon library, including the new extension framework. For more detailed examples and use cases, see the Quickstart Guide and the samples directory.
Last updated
Was this helpful?