Skip to main content

A library for converting CSVs to vCards (vCard 3.0 and 4.0)

Project description

csv2vcard

A Python library for converting CSV files to vCard format (3.0 and 4.0).

Create vCards from a spreadsheet of contacts - useful for business cards, QR codes, CRM imports, or transferring contacts between systems.

Features

  • vCard 3.0 and 4.0 support - Generate either format
  • Command-line interface - Convert files directly from terminal
  • Library API - Use programmatically in your Python code
  • Type hints - Full typing support for IDE autocomplete
  • Security - Input validation and path traversal protection
  • Zero dependencies - Core library uses only Python stdlib

Installation

# Basic installation (library only)
pip install csv2vcard

# With CLI support
pip install csv2vcard[cli]

Quick Start

Command Line

# Convert a CSV file to vCards
csv2vcard convert contacts.csv

# Specify output directory and vCard version
csv2vcard convert contacts.csv -o ./vcards -V 4.0

# Use semicolon delimiter
csv2vcard convert contacts.csv -d ";"

# Create a test vCard (Forrest Gump)
csv2vcard test

Python Library

from csv2vcard import csv2vcard, test_csv2vcard

# Basic usage - creates vCards in ./export/
csv2vcard("contacts.csv", ",")

# With options
from csv2vcard.models import VCardVersion

csv2vcard(
    "contacts.csv",
    ",",
    output_dir="./vcards",
    version=VCardVersion.V4_0,
)

# Test with sample contact
test_csv2vcard()

CSV Format

Your CSV file should have these column headers:

last_name,first_name,title,org,phone,email,website,street,city,p_code,country

Required columns: last_name, first_name

Optional columns: title, org, phone, email, website, street, city, p_code, country

Example CSV

last_name,first_name,title,org,phone,email,website,street,city,p_code,country
Gump,Forrest,Shrimp Man,Bubba Gump Shrimp Co.,+1234567890,forrest@example.com,https://example.com,42 Plantation St.,Baytown,30314,USA
Doe,Jane,Developer,Tech Corp,+0987654321,jane@example.com,https://jane.dev,123 Main St.,New York,10001,USA

CLI Reference

csv2vcard convert [OPTIONS] CSV_FILE

Options:
  -d, --delimiter TEXT      CSV field delimiter (default: ",")
  -o, --output PATH         Output directory (default: ./export/)
  -V, --vcard-version TEXT  vCard version: 3.0 or 4.0 (default: 3.0)
  --strict                  Exit on validation errors
  -v, --verbose             Enable verbose output
  --version                 Show version and exit
  --help                    Show help message

API Reference

Main Functions

from csv2vcard import csv2vcard, test_csv2vcard
from csv2vcard.models import VCardVersion

# Convert CSV to vCards
files = csv2vcard(
    csv_filename,           # Path to CSV file
    csv_delimiter=",",      # Field delimiter
    output_dir=None,        # Output directory (default: ./export/)
    version=VCardVersion.V3_0,  # vCard version
    strict=False,           # Raise on validation errors
)
# Returns: List[Path] of created vCard files

# Test with sample contact
test_csv2vcard(
    output_dir=None,
    version=VCardVersion.V3_0,
)

Models

from csv2vcard.models import Contact, VCardVersion, VCardOutput

# Create a contact programmatically
contact = Contact(
    last_name="Doe",
    first_name="John",
    email="john@example.com",
)

# Or from a dictionary
contact = Contact.from_dict({"last_name": "Doe", "first_name": "John"})

# vCard versions
VCardVersion.V3_0  # vCard 3.0 (RFC 2426)
VCardVersion.V4_0  # vCard 4.0 (RFC 6350)

Requirements

  • Python 3.9 or higher
  • For CLI: typer (installed with csv2vcard[cli])

License

MIT License - see LICENSE.txt

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

csv2vcard-0.4.0.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csv2vcard-0.4.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file csv2vcard-0.4.0.tar.gz.

File metadata

  • Download URL: csv2vcard-0.4.0.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for csv2vcard-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2f2a1088b36353fae77df25db6a859522789ce1f28def34147a341267570e7bb
MD5 65143fb5679e5b3581307cc85f98255f
BLAKE2b-256 2a6abe9063cb60dc9a74f71d1272bc14ca16db82050b0631dd5ae56d2a719728

See more details on using hashes here.

File details

Details for the file csv2vcard-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: csv2vcard-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for csv2vcard-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eeeee44270952c96da4f360fc4a0fbe7375571c1e95196bcadb842ab7ecdab05
MD5 1beb97ab3ae36f024ad5cbc44035cf74
BLAKE2b-256 0e8542f9916ba42c0f8db5bd7e6390575035d27d5b760e8a27a88850fd29d525

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