📊 Data Module

The Data module provides convenient tools for reading, writing, and managing structured data. It supports CSV, Excel, JSON, XML, and YAML files, along with useful file information utilities.

Features
  • 📄 CSV Read & Write
  • 📗 Excel Read & Write
  • 📦 JSON Read & Write
  • 🧩 XML Read & Write
  • 📝 YAML Read & Write
  • 📏 File Size
  • ✅ File Exists
  • 🏷️ File Extension
  • ✔️ Validate File
  • 📄 Filename
  • ✂️ Filename Stem

🚀 Quick Example

Read a CSV file into a DataFrame.

💻 Code

import allkitpy

df = allkitpy.data.csv.read(
    "employees.csv"
)

print(df.head())

📤 Output


   Name   Age
0 Alice   24
1 Bob     31

📚 Functions


📄 csv.read()

Read a CSV file into a pandas DataFrame.

💻 Code

import allkitpy

df = allkitpy.data.csv.read(
    "employees.csv"
)

print(df)

📤 Output


   Name   Age
0 Alice   24
1 Bob     31
2 John    27

💾 csv.write()

Save a pandas DataFrame as a CSV file.

💻 Code

import pandas as pd
import allkitpy

df = pd.DataFrame({

    "Name":[
        "Alice",
        "Bob"
    ],

    "Age":[
        24,
        31
    ]

})

allkitpy.data.csv.write(
    df,
    "employees.csv"
)

📤 Output


employees.csv
saved successfully

📗 excel.read()

Read an Excel worksheet into a pandas DataFrame.

💻 Code

import allkitpy

df = allkitpy.data.excel.read(
    "employees.xlsx"
)

print(df)

📤 Output


   Name   Age
0 Alice   24
1 Bob     31
2 John    27

💾 excel.write()

Save a pandas DataFrame as an Excel workbook.

💻 Code

import pandas as pd
import allkitpy

df = pd.DataFrame({

    "Name":[
        "Alice",
        "Bob"
    ],

    "Age":[
        24,
        31
    ]

})

allkitpy.data.excel.write(
    df,
    "employees.xlsx"
)

📤 Output


employees.xlsx
saved successfully

📦 json.read()

Read a JSON file into a Python dictionary or list.

💻 Code

import allkitpy

config = allkitpy.data.json.read(
    "config.json"
)

print(config)

📤 Output

{
    "theme":"dark",
    "language":"en"
}

💾 json.write()

Write a dictionary or list to a JSON file.

💻 Code

import allkitpy

settings = {

    "theme":"dark",

    "language":"en"

}

allkitpy.data.json.write(

    settings,

    "settings.json"

)

📤 Output


settings.json
saved successfully

🧩 xml.read()

Read and parse an XML document.

💻 Code

import allkitpy

tree = allkitpy.data.xml.read(
    "books.xml"
)

root = tree.getroot()

print(root.tag)

📤 Output

books

💾 xml.write()

Save an XML tree to a file.

💻 Code

import allkitpy

tree = allkitpy.data.xml.read(
    "books.xml"
)

allkitpy.data.xml.write(
    tree,
    "output.xml"
)

📤 Output


output.xml
saved successfully

📝 yaml.read()

Read a YAML document into Python objects.

💻 Code

import allkitpy

config = allkitpy.data.yaml.read(
    "config.yaml"
)

print(config)

📤 Output

{
    "theme":"dark",
    "language":"en"
}

💾 yaml.write()

Write a dictionary or list to a YAML document.

💻 Code

import allkitpy

config = {

    "theme":"dark",

    "language":"en"

}

allkitpy.data.yaml.write(

    config,

    "config.yaml"

)

📤 Output


config.yaml
saved successfully

📏 size()

Return the size of a data file in bytes.

💻 Code

import allkitpy

size = allkitpy.data.size(
    "employees.csv"
)

print(size)

📤 Output

2048

✅ exists()

Check whether a data file exists.

💻 Code

import allkitpy

print(

    allkitpy.data.exists(
        "config.json"
    )

)

📤 Output

True

🏷️ extension()

Return the extension of a file.

💻 Code

import allkitpy

ext = allkitpy.data.extension(
    "employees.xlsx"
)

print(ext)

📤 Output

.xlsx

✔️ validate_file()

Verify that a file exists before attempting to read or process it.

💻 Code

import allkitpy

allkitpy.data.validate_file(
    "employees.csv"
)

📤 Output

No output
(File is valid)

📄 filename()

Return the filename from a path.

💻 Code

import allkitpy

name = allkitpy.data.filename(
    "data/employees.csv"
)

print(name)

📤 Output

employees.csv

✂️ stem()

Return the filename without its extension.

💻 Code

import allkitpy

name = allkitpy.data.stem(
    "employees.csv"
)

print(name)

📤 Output

employees

📘 Module Summary

The Data module provides a unified interface for working with common structured data formats. It allows you to read, write, and manage CSV, Excel, JSON, XML, and YAML files while also providing helpful file utilities such as checking existence, retrieving file sizes, determining extensions, validating files, and extracting filenames.

Supported Formats
  • 📄 CSV
  • 📗 Excel (.xlsx)
  • 📦 JSON
  • 🧩 XML
  • 📝 YAML