vcon 0.3.4__tar.gz → 0.3.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
vcon-0.3.6/PKG-INFO ADDED
@@ -0,0 +1,481 @@
1
+ Metadata-Version: 2.1
2
+ Name: vcon
3
+ Version: 0.3.6
4
+ Summary: The vCon library
5
+ License: MIT
6
+ Author: Thomas McCarthy-Howe
7
+ Author-email: ghostofbasho@gmail.com
8
+ Requires-Python: >=3.8,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Dist: authlib (>=1.3.2,<2.0.0)
17
+ Requires-Dist: pydash (>=8.0.3,<9.0.0)
18
+ Requires-Dist: pytest (>=8.3.2,<9.0.0)
19
+ Requires-Dist: pytest-cov (>=5.0.0,<6.0.0)
20
+ Requires-Dist: pytest-mock (>=3.14.0,<4.0.0)
21
+ Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
22
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
23
+ Requires-Dist: uuid6 (>=2024.7.10,<2025.0.0)
24
+ Description-Content-Type: text/markdown
25
+
26
+ # vCon Python Library
27
+
28
+ The vCon (Virtual Conversation) library is a powerful Python tool designed to capture, structure, and manage conversation data in a standardized format. It provides a robust set of features for creating, manipulating, and analyzing digital representations of conversations, making it particularly useful for applications in customer service, call centers, chat systems, and any scenario where structured conversation data is valuable.
29
+
30
+ At its core, the vCon library allows you to create vCon objects, which serve as containers for all elements of a conversation. These objects can include multiple parties (participants in the conversation), a series of dialogs (individual messages or utterances), metadata (such as tags for easy categorization), attachments (like transcripts or other related files), and even analysis data (such as sentiment analysis results).
31
+
32
+ Key capabilities of the vCon library include:
33
+
34
+ 1. Creating and managing vCon objects with a flexible, extensible structure.
35
+ 2. Adding and retrieving conversation participants (parties) with various attributes.
36
+ 3. Recording and organizing dialog entries with timestamps, content, and sender information.
37
+ 4. Attaching metadata and tags for easy categorization and searching.
38
+ 5. Including file attachments related to the conversation.
39
+ 6. Incorporating analysis data from various sources (e.g., sentiment analysis, topic classification).
40
+ 7. Signing and verifying vCon objects for data integrity and authenticity.
41
+ 8. Serializing vCon objects to and from JSON for easy storage and transmission.
42
+
43
+ The library is designed with extensibility in mind, allowing for easy integration with various analysis tools and systems. It also includes built-in support for handling different types of conversation data, including text, audio, and video.
44
+
45
+ By providing a standardized way to structure and manage conversation data, the vCon library enables powerful applications in areas such as conversation analytics, quality assurance, compliance monitoring, and machine learning model training for natural language processing tasks.
46
+
47
+ Whether you're building a customer service platform, a conversation analysis tool, or any application that deals with structured dialog data, the vCon library offers a comprehensive solution for capturing, storing, and working with conversation information in a consistent and powerful way.
48
+
49
+ ## Features
50
+
51
+ - Create and manipulate vCon objects
52
+ - Add parties, dialogs, attachments, and analysis to vCons
53
+ - Sign and verify vCons using JWS (JSON Web Signature)
54
+ - Generate UUID8 identifiers
55
+ - Pack and unpack dialogs
56
+ - Add and retrieve tags
57
+
58
+
59
+ ## Usage
60
+ # vCon API Tutorial
61
+
62
+ This tutorial will guide you through creating a vCon (Virtual Conversation) object using the vCon API. We'll cover creating a new vCon, adding parties and dialogs, attaching metadata and analysis, and finally signing and verifying the vCon.
63
+
64
+ ## Prerequisites
65
+
66
+ Before you begin, make sure you have the vCon library installed in your Python environment.
67
+
68
+ ```bash
69
+ pip install vcon # Replace with the actual package name if different
70
+ ```
71
+
72
+ ## Step 1: Import Required Modules
73
+
74
+ First, let's import the necessary modules:
75
+
76
+ ```python
77
+ import datetime
78
+ from vcon import Vcon
79
+ from vcon.party import Party
80
+ from vcon.dialog import Dialog
81
+ from vcon.party import PartyHistory
82
+ ```
83
+
84
+ ## Step 2: Create a New vCon Object
85
+
86
+ To start, we'll create a new vCon object:
87
+
88
+ ```python
89
+ vcon = Vcon.build_new()
90
+ ```
91
+
92
+ ## Step 3: Add Parties
93
+
94
+ Next, we'll add two parties to our vCon: a caller and an agent.
95
+
96
+ ```python
97
+ caller = Party(tel="+1234567890", name="Alice", role="caller")
98
+ agent = Party(tel="+1987654321", name="Bob", role="agent")
99
+ vcon.add_party(caller)
100
+ vcon.add_party(agent)
101
+ ```
102
+
103
+ ## Step 4: Add Dialogs
104
+
105
+ Now, let's add some dialog to our vCon.
106
+
107
+ ```python
108
+ start_time = datetime.datetime.now(datetime.timezone.utc)
109
+ dialog = Dialog(
110
+ type="text",
111
+ start=start_time.isoformat(),
112
+ parties=[0, 1], # Indices of the parties in the vCon
113
+ originator=0, # The caller (Alice) is the originator
114
+ mimetype="text/plain",
115
+ body="Hello, I need help with my account.",
116
+ )
117
+ vcon.add_dialog(dialog)
118
+
119
+ ```
120
+
121
+ Note that we're using ISO format strings for the datetime values and including UTC timezone information.
122
+
123
+ ## Step 5: Add Metadata
124
+
125
+ We can add metadata to our vCon using tags:
126
+
127
+ ```python
128
+ vcon.add_tag("customer_id", "12345")
129
+ vcon.add_tag("interaction_id", "INT-001")
130
+ ```
131
+
132
+ ## Step 6: Add an Attachment
133
+
134
+ Let's add a transcript as an attachment:
135
+
136
+ ```python
137
+ transcript = "Alice: Hello, I need help with my account.\nBob: Certainly! I'd be happy to help. Can you please provide your account number?"
138
+ vcon.add_attachment(body=transcript, type="transcript", encoding="none")
139
+ ```
140
+
141
+ ## Step 7: Add Analysis
142
+
143
+ We can also add analysis data to our vCon. Here's an example of adding sentiment analysis:
144
+
145
+ ```python
146
+ sentiment_analysis = {
147
+ "overall_sentiment": "positive",
148
+ "customer_sentiment": "neutral",
149
+ "agent_sentiment": "positive"
150
+ }
151
+ vcon.add_analysis(
152
+ type="sentiment",
153
+ dialog=[0, 1], # Indices of the dialogs analyzed
154
+ vendor="SentimentAnalyzer",
155
+ body=sentiment_analysis,
156
+ encoding="none"
157
+ )
158
+ ```
159
+
160
+ ## Step 8: Sign and Verify the vCon
161
+
162
+ Finally, let's generate a key pair, sign the vCon, and verify the signature:
163
+
164
+ ```python
165
+ # Generate a key pair for signing
166
+ private_key, public_key = Vcon.generate_key_pair()
167
+
168
+ # Sign the vCon
169
+ vcon.sign(private_key)
170
+
171
+ # Verify the signature
172
+ is_valid = vcon.verify(public_key)
173
+ print(f"Signature is valid: {is_valid}")
174
+ ```
175
+
176
+ ## Step 9: Serialize to JSON
177
+
178
+ To see the final result, we can serialize our vCon to JSON:
179
+
180
+ ```python
181
+ print(vcon.to_json())
182
+ ```
183
+
184
+ ## Complete Example
185
+
186
+ Here's the complete example putting all these steps together:
187
+
188
+ ```python
189
+ import datetime
190
+ from vcon import Vcon
191
+ from vcon.party import Party
192
+ from vcon.dialog import Dialog
193
+ from vcon.party import PartyHistory
194
+
195
+ def main():
196
+ # Create a new vCon object
197
+ vcon = Vcon.build_new()
198
+
199
+ # Add parties
200
+ caller = Party(tel="+1234567890", name="Alice", role="caller")
201
+ agent = Party(tel="+1987654321", name="Bob", role="agent")
202
+ vcon.add_party(caller)
203
+ vcon.add_party(agent)
204
+
205
+ # Add a dialog
206
+ start_time = datetime.datetime.now(datetime.timezone.utc)
207
+ dialog = Dialog(
208
+ type="text",
209
+ start=start_time.isoformat(),
210
+ parties=[0, 1], # Indices of the parties in the vCon
211
+ originator=0, # The caller (Alice) is the originator
212
+ mimetype="text/plain",
213
+ body="Hello, I need help with my account.",
214
+ )
215
+ vcon.add_dialog(dialog)
216
+
217
+ # Add a response from the agent
218
+ response_time = start_time + datetime.timedelta(minutes=1)
219
+ response = Dialog(
220
+ type="text",
221
+ start=response_time.isoformat(),
222
+ parties=[0, 1],
223
+ originator=1, # The agent (Bob) is the originator
224
+ mimetype="text/plain",
225
+ body="Certainly! I'd be happy to help. Can you please provide your account number?",
226
+ )
227
+ vcon.add_dialog(response)
228
+
229
+ # Add some metadata
230
+ vcon.add_tag("customer_id", "12345")
231
+ vcon.add_tag("interaction_id", "INT-001")
232
+
233
+ # Add an attachment (e.g., a transcript)
234
+ transcript = "Alice: Hello, I need help with my account.\nBob: Certainly! I'd be happy to help. Can you please provide your account number?"
235
+ vcon.add_attachment(body=transcript, type="transcript", encoding="none")
236
+
237
+ # Add some analysis (e.g., sentiment analysis)
238
+ sentiment_analysis = {
239
+ "overall_sentiment": "positive",
240
+ "customer_sentiment": "neutral",
241
+ "agent_sentiment": "positive"
242
+ }
243
+ vcon.add_analysis(
244
+ type="sentiment",
245
+ dialog=[0, 1], # Indices of the dialogs analyzed
246
+ vendor="SentimentAnalyzer",
247
+ body=sentiment_analysis,
248
+ encoding="none"
249
+ )
250
+
251
+ # Generate a key pair for signing
252
+ private_key, public_key = Vcon.generate_key_pair()
253
+
254
+ # Sign the vCon
255
+ vcon.sign(private_key)
256
+
257
+ # Verify the signature
258
+ is_valid = vcon.verify(public_key)
259
+ print(f"Signature is valid: {is_valid}")
260
+
261
+ # Print the vCon as JSON
262
+ print(vcon.to_json())
263
+
264
+ if __name__ == "__main__":
265
+ main()
266
+ ```
267
+
268
+ # vCon Python Library API Documentation
269
+
270
+ ## Table of Contents
271
+
272
+ 1. [Vcon Class](#vcon-class)
273
+ 2. [Dialog Class](#dialog-class)
274
+ 3. [Party Class](#party-class)
275
+ 4. [PartyHistory Class](#partyhistory-class)
276
+ 5. [Constants](#constants)
277
+
278
+ ## Vcon Class
279
+
280
+ The `Vcon` class is the root class representing a vCon (Virtual Conversation) object.
281
+
282
+ ### Constructor
283
+
284
+ ```python
285
+ Vcon(vcon_dict: dict = {})
286
+ ```
287
+
288
+ Initializes a Vcon object from a dictionary.
289
+
290
+ ### Class Methods
291
+
292
+ - `build_from_json(json_string: str) -> Vcon`: Initialize a Vcon object from a JSON string.
293
+ - `build_new() -> Vcon`: Initialize a Vcon object with default values.
294
+ - `generate_key_pair() -> tuple`: Generate a new RSA key pair for signing vCons.
295
+
296
+ ### Instance Methods
297
+
298
+ - `to_json() -> str`: Serialize the vCon to a JSON string.
299
+ - `to_dict() -> dict`: Serialize the vCon to a dictionary.
300
+ - `dumps() -> str`: Alias for `to_json()`.
301
+ - `get_tag(tag_name: str) -> Optional[dict]`: Returns the value of a tag by name.
302
+ - `add_tag(tag_name: str, tag_value: str) -> None`: Adds a tag to the vCon.
303
+ - `find_attachment_by_type(type: str) -> Optional[dict]`: Finds an attachment by type.
304
+ - `add_attachment(body: Union[dict, list, str], type: str, encoding: str = "none") -> None`: Adds an attachment to the vCon.
305
+ - `find_analysis_by_type(type: str) -> Any | None`: Finds an analysis by type.
306
+ - `add_analysis(type: str, dialog: Union[list, int], vendor: str, body: Union[dict, list, str], encoding: str = "none", extra: dict = {}) -> None`: Adds analysis data to the vCon.
307
+ - `add_party(party: Party) -> None`: Adds a party to the vCon.
308
+ - `find_party_index(by: str, val: str) -> Optional[int]`: Find the index of a party in the vCon given a key-value pair.
309
+ - `find_dialog(by: str, val: str) -> Optional[Dialog]`: Find a dialog in the vCon given a key-value pair.
310
+ - `add_dialog(dialog: Dialog) -> None`: Add a dialog to the vCon.
311
+ - `sign(private_key: Union[rsa.RSAPrivateKey, bytes]) -> None`: Sign the vCon using JWS.
312
+ - `verify(public_key: Union[rsa.RSAPublicKey, bytes]) -> bool`: Verify the JWS signature of the vCon.
313
+
314
+ ### Properties
315
+
316
+ - `tags: Optional[dict]`: Returns the tags attachment.
317
+ - `parties: list[Party]`: Returns the list of parties.
318
+ - `dialog: list`: Returns the list of dialogs.
319
+ - `attachments: list`: Returns the list of attachments.
320
+ - `analysis: list`: Returns the list of analyses.
321
+ - `uuid: str`: Returns the UUID of the vCon.
322
+ - `vcon: str`: Returns the vCon version.
323
+ - `subject: Optional[str]`: Returns the subject of the vCon.
324
+ - `created_at`: Returns the creation timestamp of the vCon.
325
+ - `updated_at`: Returns the last update timestamp of the vCon.
326
+ - `redacted`: Returns the redacted information of the vCon.
327
+ - `appended`: Returns the appended information of the vCon.
328
+ - `group`: Returns the group information of the vCon.
329
+ - `meta`: Returns the metadata of the vCon.
330
+
331
+ ### Static Methods
332
+
333
+ - `uuid8_domain_name(domain_name: str) -> str`: Generate a UUID8 from a domain name.
334
+ - `uuid8_time(custom_c_62_bits: int) -> str`: Generate a UUID8 from a custom 62-bit integer.
335
+
336
+ ## Dialog Class
337
+
338
+ The `Dialog` class represents a dialog in the system.
339
+
340
+ ### Constructor
341
+
342
+ ```python
343
+ Dialog(type: str,
344
+ start: datetime,
345
+ parties: List[int],
346
+ originator: Optional[int] = None,
347
+ mimetype: Optional[str] = None,
348
+ filename: Optional[str] = None,
349
+ body: Optional[str] = None,
350
+ encoding: Optional[str] = None,
351
+ url: Optional[str] = None,
352
+ alg: Optional[str] = None,
353
+ signature: Optional[str] = None,
354
+ disposition: Optional[str] = None,
355
+ party_history: Optional[List[PartyHistory]] = None,
356
+ transferee: Optional[int] = None,
357
+ transferor: Optional[int] = None,
358
+ transfer_target: Optional[int] = None,
359
+ original: Optional[int] = None,
360
+ consultation: Optional[int] = None,
361
+ target_dialog: Optional[int] = None,
362
+ campaign: Optional[str] = None,
363
+ interaction: Optional[str] = None,
364
+ skill: Optional[str] = None,
365
+ duration: Optional[float] = None,
366
+ meta: Optional[dict] = None)
367
+ ```
368
+
369
+ Initializes a Dialog object with the given parameters.
370
+
371
+ ### Methods
372
+
373
+ - `to_dict()`: Returns a dictionary representation of the Dialog object.
374
+ - `add_external_data(url: str, filename: str, mimetype: str) -> None`: Adds external data to the dialog.
375
+ - `add_inline_data(body: str, filename: str, mimetype: str) -> None`: Adds inline data to the dialog.
376
+ - `is_external_data() -> bool`: Checks if the dialog is an external data dialog.
377
+ - `is_inline_data() -> bool`: Checks if the dialog is an inline data dialog.
378
+ - `is_text() -> bool`: Checks if the dialog is a text dialog.
379
+ - `is_audio() -> bool`: Checks if the dialog is an audio dialog.
380
+ - `is_video() -> bool`: Checks if the dialog is a video dialog.
381
+ - `is_email() -> bool`: Checks if the dialog is an email dialog.
382
+ - `is_external_data_changed() -> bool`: Checks if the external data dialog's contents have changed.
383
+ - `to_inline_data() -> None`: Converts the dialog from an external data dialog to an inline data dialog.
384
+
385
+ ## Party Class
386
+
387
+ The `Party` class represents a party in the system.
388
+
389
+ ### Constructor
390
+
391
+ ```python
392
+ Party(tel: Optional[str] = None,
393
+ stir: Optional[str] = None,
394
+ mailto: Optional[str] = None,
395
+ name: Optional[str] = None,
396
+ validation: Optional[str] = None,
397
+ gmlpos: Optional[str] = None,
398
+ civicaddress: Optional[CivicAddress] = None,
399
+ uuid: Optional[str] = None,
400
+ role: Optional[str] = None,
401
+ contact_list: Optional[str] = None,
402
+ meta: Optional[dict] = None)
403
+ ```
404
+
405
+ Initializes a Party object with the given parameters.
406
+
407
+ ### Methods
408
+
409
+ - `to_dict()`: Returns a dictionary representation of the Party object.
410
+
411
+ ## PartyHistory Class
412
+
413
+ The `PartyHistory` class represents the history of a party's participation in a dialog.
414
+
415
+ ### Constructor
416
+
417
+ ```python
418
+ PartyHistory(party: int, event: str, time: datetime)
419
+ ```
420
+
421
+ Initializes a PartyHistory object with the given parameters.
422
+
423
+ ### Methods
424
+
425
+ - `to_dict()`: Returns a dictionary representation of the PartyHistory object.
426
+
427
+ ## Constants
428
+
429
+ - `MIME_TYPES`: A list of supported MIME types for dialogs.
430
+
431
+ ```python
432
+ MIME_TYPES = [
433
+ "text/plain",
434
+ "audio/x-wav",
435
+ "audio/x-mp3",
436
+ "audio/x-mp4",
437
+ "audio/ogg",
438
+ "video/x-mp4",
439
+ "video/ogg",
440
+ "multipart/mixed",
441
+ "message/external-body",
442
+ ]
443
+ ```
444
+
445
+
446
+ ## Contributing
447
+
448
+ Contributions to the vCon library are welcome! Please submit pull requests or open issues on the GitHub repository.
449
+
450
+ ## License
451
+
452
+ This project is licensed under the MIT License:
453
+
454
+ MIT License
455
+
456
+ Copyright (c) 2023 Thomas McCarthy-Howe
457
+
458
+ Permission is hereby granted, free of charge, to any person obtaining a copy
459
+ of this software and associated documentation files (the "Software"), to deal
460
+ in the Software without restriction, including without limitation the rights
461
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
462
+ copies of the Software, and to permit persons to whom the Software is
463
+ furnished to do so, subject to the following conditions:
464
+
465
+ The above copyright notice and this permission notice shall be included in all
466
+ copies or substantial portions of the Software.
467
+
468
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
469
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
470
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
471
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
472
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
473
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
474
+ SOFTWARE.
475
+
476
+ ## Contact
477
+
478
+ For questions or support, please contact:
479
+
480
+ Thomas McCarthy-Howe
481
+ Email: ghostofbasho@gmail.com