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.1.tar.gz (10.9 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.1-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for csv_to_yaml-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c790a93dbddd9b4ffce774b62e9e579b97e3eba4dae538811dc4126b05f2f156
MD5 0af5f73bf68e59e9a2f0df931cffb012
BLAKE2b-256 3a085e98be38e3d545e195da660f2e5008f3b188a5e2809eca7800af0905a69a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for csv_to_yaml-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4826e753c35ae4c7297d159c4354c43649e3605619ab95f6f70455206b5bcddc
MD5 5a297052e69fa146c1cbfbc17629a286
BLAKE2b-256 fe83ee2762d76c8712c430fffd5d14478325ff10e9f30b45dfed61182ba1765a

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