Skip to main content

Lightweight CSV to YAML and YAML to CSV converter

Project description

csv-to-yaml

Lightweight CSV to YAML and YAML to CSV converter.

Installation

pip install csv-to-yaml

Or with uv:

uv add csv-to-yaml

Requirements

  • Python >= 3.13
  • PyYAML >= 6.0

CLI Usage

# Convert CSV to YAML (output to stdout)
csv-to-yaml input.csv

# Convert YAML to CSV (output to stdout)
csv-to-yaml input.yaml

# Specify output file
csv-to-yaml input.csv -o output.yaml
csv-to-yaml input.yaml -o output.csv

# Explicitly specify output format
csv-to-yaml input.csv -f yaml
csv-to-yaml input.yaml -f csv

Python API

Convert CSV to YAML

from main import csv_to_yaml

# From file path
data = csv_to_yaml("data.csv")  # Returns list of dicts
yaml_str = csv_to_yaml("data.csv", as_string=True)  # Returns YAML string

# From string
csv_data = "name,age\nAlice,30\nBob,25"
data = csv_to_yaml(csv_data)

Convert YAML to CSV

from main import yaml_to_csv

# From file path
data = yaml_to_csv("data.yaml")  # Returns list of dicts
csv_str = yaml_to_csv("data.yaml", as_string=True)  # Returns CSV string

# From string
yaml_data = "- name: Alice\n  age: 30"
data = yaml_to_csv(yaml_data)

File-to-File Conversion

from main import csv_file_to_yaml_file, yaml_file_to_csv_file

csv_file_to_yaml_file("input.csv", "output.yaml")
yaml_file_to_csv_file("input.yaml", "output.csv")

Unicode Support

Full Unicode support including CJK characters:

csv_data = "이름,나이\n홍길동,30"
result = csv_to_yaml(csv_data)
# [{'이름': '홍길동', '나이': '30'}]

Development

# Install dev dependencies
uv sync

# Run tests
pytest

License

MIT

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

csv_to_yaml-0.1.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

csv_to_yaml-0.1.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file csv_to_yaml-0.1.0.tar.gz.

File metadata

  • Download URL: csv_to_yaml-0.1.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for csv_to_yaml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8a0028f61146010170d3c9a049be435ff94ac24506bc70c264c84e3866585f92
MD5 9c8372d561fb73bc8f0f5d5144493435
BLAKE2b-256 824b2192a5df858e031db3866c3997129ed2d177772792575ad7a1d8ab83edfe

See more details on using hashes here.

File details

Details for the file csv_to_yaml-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for csv_to_yaml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89c2ab1a30a4ce47d762af034113bd10003130f2c124c94568449fe645a96fd6
MD5 9736ef81a915e32b2d0e6975de5e05e3
BLAKE2b-256 f86ef469b5880fbb4e33a6d9cb5a37239cf1f33467faa4a8dfd5bc34a26027f1

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