Serialization Module¶
The rite.serialization module provides utilities for working with various data formats including JSON, CSV, TOML, Pickle, and INI files.
Overview¶
serialization ¶
Serialization Module¶
Data serialization and deserialization utilities.
This module provides comprehensive utilities for working with various data formats including JSON, CSV, INI, Pickle, and TOML using only Python's standard library.
Submodules¶
- json: JSON file and string operations
- csv: CSV file operations with delimiter detection
- ini: INI/config file operations
- pickle: Python object serialization
- toml: TOML file operations (Python 3.11+)
Examples¶
from rite.serialization import json_load, csv_read data = json_load("data.json") rows = csv_read("data.csv")
Notes¶
Legacy classes JSONHandler, INIHandler, and detect_delimiter are still available for backward compatibility.
Modules¶
csv ¶
CSV Module¶
CSV file operations.
This submodule provides utilities for reading and writing CSV files with automatic delimiter detection.
Examples¶
from rite.serialization.csv import csv_read, csv_write data = csv_read("input.csv") csv_write("output.csv", data)
Modules¶
csv_detect_delimiter ¶
CSV Delimiter Detector¶
Detect delimiter from filename.
Examples¶
from rite.serialization.csv import csv_detect_delimiter csv_detect_delimiter("data.tsv") '\t'
Detect delimiter from filename extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
CSV filename or path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Delimiter character (tab or comma). |
Examples:
>>> csv_detect_delimiter("data.csv")
','
>>> csv_detect_delimiter("data.tsv")
'\t'
>>> csv_detect_delimiter("path/to/data.tsv")
'\t'
Notes
Returns tab for .tsv, comma otherwise.
csv_read ¶
CSV Reader¶
Read CSV file to list of dicts.
Examples¶
from rite.serialization.csv import csv_read rows = csv_read("data.csv")
Read CSV file to list of dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to CSV file. |
required |
delimiter
|
str
|
CSV delimiter character. |
','
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of row dictionaries. |
Examples:
>>> csv_read("data.csv")
[{'col1': 'val1', 'col2': 'val2'}, ...]
>>> csv_read("data.tsv", delimiter="\t")
[...]
Notes
Uses DictReader for named columns. First row is header.
csv_write ¶
CSV Writer¶
Write list of dicts to CSV file.
Examples¶
from rite.serialization.csv import csv_write data = [{"col1": "val1", "col2": "val2"}] csv_write("output.csv", data)
Write list of dictionaries to CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to output CSV file. |
required |
data
|
list[dict[str, Any]]
|
List of row dictionaries. |
required |
delimiter
|
str
|
CSV delimiter character. |
','
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
>>> data = [{"col1": "val1", "col2": "val2"}]
>>> csv_write("output.csv", data)
>>> csv_write("output.tsv", data, delimiter="\t")
Notes
Creates parent directories if needed. Header from first row keys.
csv_detect_delimiter ¶
CSV Delimiter Detector¶
Detect delimiter from filename.
Examples¶
from rite.serialization.csv import csv_detect_delimiter csv_detect_delimiter("data.tsv") '\t'
Functions¶
csv_detect_delimiter ¶
Detect delimiter from filename extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
CSV filename or path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Delimiter character (tab or comma). |
Examples:
>>> csv_detect_delimiter("data.csv")
','
>>> csv_detect_delimiter("data.tsv")
'\t'
>>> csv_detect_delimiter("path/to/data.tsv")
'\t'
Notes
Returns tab for .tsv, comma otherwise.
csv_read ¶
CSV Reader¶
Read CSV file to list of dicts.
Examples¶
from rite.serialization.csv import csv_read rows = csv_read("data.csv")
Functions¶
csv_read ¶
Read CSV file to list of dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to CSV file. |
required |
delimiter
|
str
|
CSV delimiter character. |
','
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of row dictionaries. |
Examples:
>>> csv_read("data.csv")
[{'col1': 'val1', 'col2': 'val2'}, ...]
>>> csv_read("data.tsv", delimiter="\t")
[...]
Notes
Uses DictReader for named columns. First row is header.
csv_write ¶
CSV Writer¶
Write list of dicts to CSV file.
Examples¶
from rite.serialization.csv import csv_write data = [{"col1": "val1", "col2": "val2"}] csv_write("output.csv", data)
Functions¶
csv_write ¶
Write list of dictionaries to CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to output CSV file. |
required |
data
|
list[dict[str, Any]]
|
List of row dictionaries. |
required |
delimiter
|
str
|
CSV delimiter character. |
','
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
>>> data = [{"col1": "val1", "col2": "val2"}]
>>> csv_write("output.csv", data)
>>> csv_write("output.tsv", data, delimiter="\t")
Notes
Creates parent directories if needed. Header from first row keys.
ini ¶
INI Module¶
INI configuration file operations.
This submodule provides utilities for reading and writing INI/config files with section and key-value operations.
Examples¶
from rite.serialization.ini import ini_read, ini_write config = ini_read("config.ini") ini_write("output.ini", config)
Modules¶
ini_get ¶
INI Get Value¶
Get value from INI configuration.
Examples¶
from rite.serialization.ini import ini_get ini_get("config.ini", "section", "key") 'value'
Get value from INI file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to INI file. |
required |
section
|
str
|
Section name. |
required |
key
|
str
|
Key name. |
required |
default
|
str | None
|
Default value if not found. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Value string or default. |
Examples:
>>> ini_get("config.ini", "section", "key")
'value'
>>> ini_get("config.ini", "section", "missing", "default")
'default'
Notes
Returns default if section or key not found.
ini_read ¶
INI Reader¶
Read INI configuration file.
Examples¶
from rite.serialization.ini import ini_read config = ini_read("config.ini")
Read INI file to nested dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to INI file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, str]]
|
Nested dictionary of sections and key-value pairs. |
Examples:
Notes
Uses ConfigParser for INI parsing. Returns nested dict structure.
ini_set ¶
INI Set Value¶
Set value in INI configuration.
Examples¶
from rite.serialization.ini import ini_set ini_set("config.ini", "section", "key", "value")
Set value in INI file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to INI file. |
required |
section
|
str
|
Section name. |
required |
key
|
str
|
Key name. |
required |
value
|
str
|
Value to set. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Notes
Creates section if not exists. Creates file if not exists.
ini_write ¶
INI Writer¶
Write nested dict to INI file.
Examples¶
from rite.serialization.ini import ini_write config = {"section": {"key": "value"}} ini_write("config.ini", config)
Write nested dictionary to INI file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to output INI file. |
required |
data
|
dict[str, dict[str, str]]
|
Nested dict of sections and key-value pairs. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Notes
Creates parent directories if needed. Uses ConfigParser for formatting.
ini_get ¶
INI Get Value¶
Get value from INI configuration.
Examples¶
from rite.serialization.ini import ini_get ini_get("config.ini", "section", "key") 'value'
Functions¶
ini_get ¶
Get value from INI file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to INI file. |
required |
section
|
str
|
Section name. |
required |
key
|
str
|
Key name. |
required |
default
|
str | None
|
Default value if not found. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Value string or default. |
Examples:
>>> ini_get("config.ini", "section", "key")
'value'
>>> ini_get("config.ini", "section", "missing", "default")
'default'
Notes
Returns default if section or key not found.
ini_read ¶
INI Reader¶
Read INI configuration file.
Examples¶
from rite.serialization.ini import ini_read config = ini_read("config.ini")
Functions¶
ini_read ¶
Read INI file to nested dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to INI file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, str]]
|
Nested dictionary of sections and key-value pairs. |
Examples:
Notes
Uses ConfigParser for INI parsing. Returns nested dict structure.
ini_set ¶
INI Set Value¶
Set value in INI configuration.
Examples¶
from rite.serialization.ini import ini_set ini_set("config.ini", "section", "key", "value")
Functions¶
ini_set ¶
Set value in INI file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to INI file. |
required |
section
|
str
|
Section name. |
required |
key
|
str
|
Key name. |
required |
value
|
str
|
Value to set. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Notes
Creates section if not exists. Creates file if not exists.
ini_write ¶
INI Writer¶
Write nested dict to INI file.
Examples¶
from rite.serialization.ini import ini_write config = {"section": {"key": "value"}} ini_write("config.ini", config)
Functions¶
ini_write ¶
Write nested dictionary to INI file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to output INI file. |
required |
data
|
dict[str, dict[str, str]]
|
Nested dict of sections and key-value pairs. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Notes
Creates parent directories if needed. Uses ConfigParser for formatting.
json ¶
JSON Module¶
JSON serialization utilities.
This submodule provides utilities for JSON operations like loading, dumping, parsing, and validation.
Examples¶
from rite.serialization.json import json_load, json_dump data = json_load("input.json") json_dump("output.json", data)
Modules¶
json_dump ¶
JSON Dumper¶
Save JSON to file.
Examples¶
from rite.serialization.json import json_dump json_dump("output.json", {"key": "value"})
Save JSON data to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to output JSON file. |
required |
data
|
Any
|
Data to serialize. |
required |
indent
|
int | None
|
Indentation spaces (None for compact). |
2
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Notes
Creates parent directories if needed. Uses UTF-8 encoding.
json_dumps ¶
JSON Dumps¶
Serialize data to JSON string.
Examples¶
from rite.serialization.json import json_dumps json_dumps({"key": "value"}) '{"key": "value"}'
Serialize data to JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Data to serialize. |
required |
indent
|
int | None
|
Indentation spaces (None for compact). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string. |
Examples:
>>> json_dumps({"key": "value"})
'{"key": "value"}'
>>> json_dumps({"key": "value"}, indent=2)
'{\n "key": "value"\n}'
Notes
Wrapper around json.dumps.
json_load ¶
JSON Loader¶
Load JSON from file.
Examples¶
from rite.serialization.json import json_load data = json_load("data.json")
Load JSON data from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to JSON file. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Parsed JSON data. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If file doesn't exist. |
JSONDecodeError
|
If JSON is invalid. |
Examples:
Notes
Uses UTF-8 encoding.
json_loads ¶
JSON Loads¶
Parse JSON from string.
Examples¶
from rite.serialization.json import json_loads json_loads('{"key": "value"}')
json_validate ¶
JSON Validator¶
Validate JSON string.
Examples¶
from rite.serialization.json import json_validate json_validate('{"key": "value"}') True
Validate JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
JSON string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if valid JSON, False otherwise. |
Examples:
>>> json_validate('{"key": "value"}')
True
>>> json_validate('{invalid}')
False
>>> json_validate('[1, 2, 3]')
True
Notes
Returns False on any JSON decode error.
json_dump ¶
JSON Dumper¶
Save JSON to file.
Examples¶
from rite.serialization.json import json_dump json_dump("output.json", {"key": "value"})
Functions¶
json_dump ¶
Save JSON data to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to output JSON file. |
required |
data
|
Any
|
Data to serialize. |
required |
indent
|
int | None
|
Indentation spaces (None for compact). |
2
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Notes
Creates parent directories if needed. Uses UTF-8 encoding.
json_dumps ¶
JSON Dumps¶
Serialize data to JSON string.
Examples¶
from rite.serialization.json import json_dumps json_dumps({"key": "value"}) '{"key": "value"}'
Functions¶
json_dumps ¶
Serialize data to JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Data to serialize. |
required |
indent
|
int | None
|
Indentation spaces (None for compact). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string. |
Examples:
>>> json_dumps({"key": "value"})
'{"key": "value"}'
>>> json_dumps({"key": "value"}, indent=2)
'{\n "key": "value"\n}'
Notes
Wrapper around json.dumps.
json_load ¶
JSON Loader¶
Load JSON from file.
Examples¶
from rite.serialization.json import json_load data = json_load("data.json")
Functions¶
json_load ¶
Load JSON data from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to JSON file. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Parsed JSON data. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If file doesn't exist. |
JSONDecodeError
|
If JSON is invalid. |
Examples:
Notes
Uses UTF-8 encoding.
json_loads ¶
JSON Loads¶
Parse JSON from string.
Examples¶
from rite.serialization.json import json_loads json_loads('{"key": "value"}')
json_validate ¶
JSON Validator¶
Validate JSON string.
Examples¶
from rite.serialization.json import json_validate json_validate('{"key": "value"}') True
Functions¶
json_validate ¶
Validate JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
JSON string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if valid JSON, False otherwise. |
Examples:
>>> json_validate('{"key": "value"}')
True
>>> json_validate('{invalid}')
False
>>> json_validate('[1, 2, 3]')
True
Notes
Returns False on any JSON decode error.
pickle ¶
Pickle Module¶
Pickle serialization operations.
This submodule provides utilities for serializing and deserializing Python objects using the pickle protocol.
Examples¶
from rite.serialization.pickle import pickle_dump, pickle_load pickle_dump("data.pkl", {"key": "value"}) data = pickle_load("data.pkl")
Modules¶
pickle_dump ¶
Pickle Dump¶
Serialize object to pickle file.
Examples¶
from rite.serialization.pickle import pickle_dump pickle_dump("data.pkl", {"key": "value"})
pickle_dumps ¶
pickle_load ¶
pickle_dump ¶
Pickle Dump¶
Serialize object to pickle file.
Examples¶
from rite.serialization.pickle import pickle_dump pickle_dump("data.pkl", {"key": "value"})
pickle_dumps ¶
pickle_load ¶
pickle_loads ¶
toml ¶
TOML Module¶
TOML file operations.
This submodule provides utilities for reading TOML files using the stdlib tomllib (Python 3.11+). Write operations are not supported in stdlib.
Examples¶
from rite.serialization.toml import toml_load config = toml_load("config.toml")
Modules¶
toml_load ¶
TOML Load¶
Load TOML from file.
Examples¶
from rite.serialization.toml import toml_load config = toml_load("config.toml")
Load TOML from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to TOML file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed TOML as dictionary. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If Python version < 3.11. |
Examples:
Notes
Requires Python 3.11+ (tomllib). Read-only (no write support in stdlib).
toml_loads ¶
TOML Loads¶
Parse TOML from string.
Examples¶
from rite.serialization.toml import toml_loads config = toml_loads('[section]\nkey = "value"')
Parse TOML from string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
TOML string to parse. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed TOML as dictionary. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If Python version < 3.11. |
Examples:
Notes
Requires Python 3.11+ (tomllib).
toml_load ¶
TOML Load¶
Load TOML from file.
Examples¶
from rite.serialization.toml import toml_load config = toml_load("config.toml")
Functions¶
toml_load ¶
Load TOML from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to TOML file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed TOML as dictionary. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If Python version < 3.11. |
Examples:
Notes
Requires Python 3.11+ (tomllib). Read-only (no write support in stdlib).
toml_loads ¶
TOML Loads¶
Parse TOML from string.
Examples¶
from rite.serialization.toml import toml_loads config = toml_loads('[section]\nkey = "value"')
Functions¶
toml_loads ¶
Parse TOML from string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
TOML string to parse. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed TOML as dictionary. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If Python version < 3.11. |
Examples:
Notes
Requires Python 3.11+ (tomllib).
Submodules¶
JSON¶
Parse and generate JSON data.
JSON Module¶
JSON serialization utilities.
This submodule provides utilities for JSON operations like loading, dumping, parsing, and validation.
Examples¶
from rite.serialization.json import json_load, json_dump data = json_load("input.json") json_dump("output.json", data)
Modules¶
json_load ¶
JSON Loader¶
Load JSON from file.
Examples¶
from rite.serialization.json import json_load data = json_load("data.json")
Functions¶
json_load ¶
Load JSON data from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to JSON file. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Parsed JSON data. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If file doesn't exist. |
JSONDecodeError
|
If JSON is invalid. |
Examples:
Notes
Uses UTF-8 encoding.
json_loads ¶
JSON Loads¶
Parse JSON from string.
Examples¶
from rite.serialization.json import json_loads json_loads('{"key": "value"}')
json_dump ¶
JSON Dumper¶
Save JSON to file.
Examples¶
from rite.serialization.json import json_dump json_dump("output.json", {"key": "value"})
Functions¶
json_dump ¶
Save JSON data to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to output JSON file. |
required |
data
|
Any
|
Data to serialize. |
required |
indent
|
int | None
|
Indentation spaces (None for compact). |
2
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Notes
Creates parent directories if needed. Uses UTF-8 encoding.
json_dumps ¶
JSON Dumps¶
Serialize data to JSON string.
Examples¶
from rite.serialization.json import json_dumps json_dumps({"key": "value"}) '{"key": "value"}'
Functions¶
json_dumps ¶
Serialize data to JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Data to serialize. |
required |
indent
|
int | None
|
Indentation spaces (None for compact). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string. |
Examples:
>>> json_dumps({"key": "value"})
'{"key": "value"}'
>>> json_dumps({"key": "value"}, indent=2)
'{\n "key": "value"\n}'
Notes
Wrapper around json.dumps.
json_validate ¶
JSON Validator¶
Validate JSON string.
Examples¶
from rite.serialization.json import json_validate json_validate('{"key": "value"}') True
Functions¶
json_validate ¶
Validate JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
JSON string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if valid JSON, False otherwise. |
Examples:
>>> json_validate('{"key": "value"}')
True
>>> json_validate('{invalid}')
False
>>> json_validate('[1, 2, 3]')
True
Notes
Returns False on any JSON decode error.
CSV¶
Read and write CSV files.
CSV Module¶
CSV file operations.
This submodule provides utilities for reading and writing CSV files with automatic delimiter detection.
Examples¶
from rite.serialization.csv import csv_read, csv_write data = csv_read("input.csv") csv_write("output.csv", data)
Modules¶
csv_read ¶
CSV Reader¶
Read CSV file to list of dicts.
Examples¶
from rite.serialization.csv import csv_read rows = csv_read("data.csv")
Functions¶
csv_read ¶
Read CSV file to list of dictionaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to CSV file. |
required |
delimiter
|
str
|
CSV delimiter character. |
','
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of row dictionaries. |
Examples:
>>> csv_read("data.csv")
[{'col1': 'val1', 'col2': 'val2'}, ...]
>>> csv_read("data.tsv", delimiter="\t")
[...]
Notes
Uses DictReader for named columns. First row is header.
csv_write ¶
CSV Writer¶
Write list of dicts to CSV file.
Examples¶
from rite.serialization.csv import csv_write data = [{"col1": "val1", "col2": "val2"}] csv_write("output.csv", data)
Functions¶
csv_write ¶
Write list of dictionaries to CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to output CSV file. |
required |
data
|
list[dict[str, Any]]
|
List of row dictionaries. |
required |
delimiter
|
str
|
CSV delimiter character. |
','
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
>>> data = [{"col1": "val1", "col2": "val2"}]
>>> csv_write("output.csv", data)
>>> csv_write("output.tsv", data, delimiter="\t")
Notes
Creates parent directories if needed. Header from first row keys.
csv_detect_delimiter ¶
CSV Delimiter Detector¶
Detect delimiter from filename.
Examples¶
from rite.serialization.csv import csv_detect_delimiter csv_detect_delimiter("data.tsv") '\t'
Functions¶
csv_detect_delimiter ¶
Detect delimiter from filename extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
CSV filename or path. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Delimiter character (tab or comma). |
Examples:
>>> csv_detect_delimiter("data.csv")
','
>>> csv_detect_delimiter("data.tsv")
'\t'
>>> csv_detect_delimiter("path/to/data.tsv")
'\t'
Notes
Returns tab for .tsv, comma otherwise.
TOML¶
Parse TOML configuration files (Python 3.11+).
TOML Module¶
TOML file operations.
This submodule provides utilities for reading TOML files using the stdlib tomllib (Python 3.11+). Write operations are not supported in stdlib.
Examples¶
from rite.serialization.toml import toml_load config = toml_load("config.toml")
Modules¶
toml_load ¶
TOML Load¶
Load TOML from file.
Examples¶
from rite.serialization.toml import toml_load config = toml_load("config.toml")
Functions¶
toml_load ¶
Load TOML from file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to TOML file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed TOML as dictionary. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If Python version < 3.11. |
Examples:
Notes
Requires Python 3.11+ (tomllib). Read-only (no write support in stdlib).
toml_loads ¶
TOML Loads¶
Parse TOML from string.
Examples¶
from rite.serialization.toml import toml_loads config = toml_loads('[section]\nkey = "value"')
Functions¶
toml_loads ¶
Parse TOML from string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
TOML string to parse. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed TOML as dictionary. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If Python version < 3.11. |
Examples:
Notes
Requires Python 3.11+ (tomllib).
Pickle¶
Serialize and deserialize Python objects.
Pickle Module¶
Pickle serialization operations.
This submodule provides utilities for serializing and deserializing Python objects using the pickle protocol.
Examples¶
from rite.serialization.pickle import pickle_dump, pickle_load pickle_dump("data.pkl", {"key": "value"}) data = pickle_load("data.pkl")
Modules¶
pickle_dump ¶
Pickle Dump¶
Serialize object to pickle file.
Examples¶
from rite.serialization.pickle import pickle_dump pickle_dump("data.pkl", {"key": "value"})
pickle_load ¶
pickle_dumps ¶
INI¶
Read and write INI configuration files.
INI Module¶
INI configuration file operations.
This submodule provides utilities for reading and writing INI/config files with section and key-value operations.
Examples¶
from rite.serialization.ini import ini_read, ini_write config = ini_read("config.ini") ini_write("output.ini", config)
Modules¶
ini_read ¶
INI Reader¶
Read INI configuration file.
Examples¶
from rite.serialization.ini import ini_read config = ini_read("config.ini")
Functions¶
ini_read ¶
Read INI file to nested dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to INI file. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, str]]
|
Nested dictionary of sections and key-value pairs. |
Examples:
Notes
Uses ConfigParser for INI parsing. Returns nested dict structure.
ini_write ¶
INI Writer¶
Write nested dict to INI file.
Examples¶
from rite.serialization.ini import ini_write config = {"section": {"key": "value"}} ini_write("config.ini", config)
Functions¶
ini_write ¶
Write nested dictionary to INI file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to output INI file. |
required |
data
|
dict[str, dict[str, str]]
|
Nested dict of sections and key-value pairs. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Notes
Creates parent directories if needed. Uses ConfigParser for formatting.
ini_get ¶
INI Get Value¶
Get value from INI configuration.
Examples¶
from rite.serialization.ini import ini_get ini_get("config.ini", "section", "key") 'value'
Functions¶
ini_get ¶
Get value from INI file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to INI file. |
required |
section
|
str
|
Section name. |
required |
key
|
str
|
Key name. |
required |
default
|
str | None
|
Default value if not found. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
Value string or default. |
Examples:
>>> ini_get("config.ini", "section", "key")
'value'
>>> ini_get("config.ini", "section", "missing", "default")
'default'
Notes
Returns default if section or key not found.
ini_set ¶
INI Set Value¶
Set value in INI configuration.
Examples¶
from rite.serialization.ini import ini_set ini_set("config.ini", "section", "key", "value")
Functions¶
ini_set ¶
Set value in INI file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to INI file. |
required |
section
|
str
|
Section name. |
required |
key
|
str
|
Key name. |
required |
value
|
str
|
Value to set. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Notes
Creates section if not exists. Creates file if not exists.
Examples¶
JSON Operations¶
from rite.serialization import json_load, json_dump, json_validate
# Load JSON from file
data = json_load("config.json")
# Save JSON to file
json_dump({"key": "value"}, "output.json")
# Validate JSON string
is_valid = json_validate('{"valid": true}')
CSV Operations¶
from rite.serialization import csv_read, csv_write
# Read CSV file
rows = csv_read("data.csv")
# Write CSV file
csv_write("output.csv", [
["name", "age"],
["Alice", 30],
["Bob", 25]
])