A lazy Python 2/3 vcard parser built with a human-readable API
from vcfx import reader
vcard = reader("/home/rum/Programming/vcfx/fixtures/reggie-smalls-ios-v3.0.vcf")
# All field functions with plural names return generators
phones = vcard.phones()
# Out[1]:
# [<Telephone subkey="None" key="TEL" lineno="13" />,
# <Telephone subkey="None" key="TEL" lineno="14" />,
# ...,
# <Telephone subkey="item7" key="TEL" lineno="24" />]
# While the latter return singular items
vcard.fullname().value
# Out[2]: 'Reginald Smalls'
vcard.name().first
# Out[3]: 'Reginald'
phones[0].can_sms
# Out[4]: False
# You also may iterate over the vcard directly, one line at a time
for field in vcard:
print(field)
# <Begin subkey="None" key="BEGIN" lineno="0" />
# <Version subkey="None" key="VERSION" lineno="1" />
# <Prodid subkey="None" key="PRODID" lineno="2" />
# <Name subkey="None" key="N" lineno="3" />
# ...
There are still some things left to do before i call this 1.0, but the API is still entirely useable and adding support for any additional fields is rather easy (See any nodes.py
in /fields
).
- [%75] Expose getters for all fields (You can still get every field via iteration)
- [%55] Complete value parsing and assignment per spec RFC 6350, However grabbing the unparsed value with
<FieldName>.value
is possible. - [%40] Documentation of all available field APIs (I strongly encourage you to read through
vcfx.fields
if you are looking) - [%25] Complete attribute parsing of fields and assignment to human-readable names
- Testing
- Generic getters for folded items
[%100] Fold support, Currently if a field comes along thats longer than 80 characters, we die- Vcard 2.1 support (Really just need to write a
parseline2
function similar toparseline3
intokenizer.py
) - Rip the
_vAST
logic out of the file reader intokenizer.py
and put it in its own class [%100] Optimize position reader- Full X-attribute parsing
- URL support for photos
[%100] Identification ofUnknown
rows & flattening of thevAST
when iterating over the reader- Vcard construction
- [%10] Vcard validation
- In-place Vcard modification
- Fetching and storing photos
- Fetching and rewriting photos under various formats
- "Safe Mode", aka stripping out fields + values that may break interoperability
There are a couple of attributes that all fields share:
attrs :: [dict(str)]
-- list of all the attributes associated with the nodelabel :: str
-- A custom label associated with the fieldpreferred :: str
-- Whether the item is the preferred item out of it's supersetsubkey :: str
-- The subkey of the item (used in IOS)types :: [str]
-- Anytype=
attributes found with the field (i.etype=HOME
)value :: str
-- The full value of the field, used for fields that define a single value (i.eFullName().value
)
value :: str
-- Should always be "VCARD"
value :: str
-- Should always be "VCARD"
value :: str
-- A URI (defined in [RFC3986]) to a directory service where an application may pull more information from
value :: str
-- Must be one of["individual", "group", "org", "location"]
value :: str
-- a single XML 1.0 element
value :: str
-- The full name of the contact
first :: str
-- First name (Given name)last :: str
-- Last name (Surname)additional :: [str]
-- Additional names for the contactsuffixes :: [str]
-- Formal suffixesprefixes :: [str]
-- Formal prefixes
value :: [str]
-- Nicknames of the contact
b64 :: str
-- Base64 representation of the contact's photo
value :: str
value :: str
value :: str
-- A single letter. M stands for "male", F stands for "female", O stands for "other", N stands for "none or not applicable", U stands for "unknown".
b64 :: str
-- Base64 representation of the contact's photo
po_box :: str
-- The post office boxextended_address :: str
-- The extended address (e.g line2, Apt #, Ste #) of the contactlocality :: str
-- The locality of the contact (e.g "city")region :: str
-- e.g state, provincepostal_code :: str
-- The postal code (or zip code) of the contactcountry :: str
-- Full name of the country
value :: string
-- A single text value containing a phone numbercan_sms :: bool
can_call :: bool
can_fax :: bool
can_video_conference :: bool
is_TTY :: bool
value :: str
value :: str
-- URI for instant messaging and presence protocol communications
value :: str
-- eg. fr, en, de
value :: string
-- A single text value containing a URI
value :: string
-- A single text value containing information regarding the contact's timezone
value :: string
-- A single text value containing the position or job of the contact
value :: string
-- A single text value containing information regarding the function or part played by the contact
-
name :: string
-- The name of the organization the contact is a part of -
org_unit1 :: string
-- The first organizational unit of the organization the contact is a part of -
org_unit2 :: string
-- the second organizational unit of the organization the contact is a part of
value :: string
-- a generic member
value :: [string]
-- a list of tags or categories associated with this VCARD
value :: string
-- a comment associated with the vcard
value :: string
-- specifies the identifier for the product that created the vCard object.
value :: timestamp
-- Revision information about the current VCARD
value :: string
-- a globally unique identifier associated with the current VCARD
value :: string
value :: string
-- The VCARD version