Registry / data / tinsel

tinsel

JSON →
library0.3.0pypypi✓ verified 86d ago

Tinsel is a lightweight Python library designed to simplify PySpark DataFrame schema generation. It allows users to define complex PySpark schemas using familiar Python native types like `NamedTuple` and `dataclasses`, removing the need for verbose PySpark schema DSLs. The library is small, fast, and provides type shims for some Python types that might not have direct Spark equivalents. The current version is 0.3.0, with the last public update in September 2018, indicating a maintenance-level release cadence.

pip install tinsel
INSTALL
IMPORT
SIG · TINSEL
T
tinsel
datapythonv0.3.0
Install
30.6s avg
Import
499ms
Disk
500MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.517s · 505.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 30.6s · import 0.481s · 506MB
500MB installed
● package 500MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

struct
from tinsel import struct
from tinsel.schema import struct
The `struct` decorator is directly available from the top-level `tinsel` package.
transform
from tinsel import transform
import tinsel.transform
The `transform` function is a direct import from the `tinsel` package.

This quickstart demonstrates how to define a PySpark schema using Tinsel with Python's `dataclasses` and `NamedTuple`. It then converts this definition into a `StructType` compatible with PySpark and creates a DataFrame with sample data.

from dataclasses import dataclass from typing import NamedTuple, Optional, Dict, List from tinsel import struct, transform from pyspark.sql import SparkSession # Define nested schema using dataclass @struct @dataclass class UserInfo: hobby: List[str] last_seen: Optional[int] pet_ages: Dict[str, int] # Define root schema using NamedTuple @struct class User(NamedTuple): login: str age: int active: bool info: Optional[UserInfo] # Transform the Python class into a PySpark schema spark_schema = transform(User) # Prepare sample data matching the defined structure data = [ User( login="Ben", age=18, active=False, info=None ), User( login="Tom", age=32, active=True, info=UserInfo( hobby=["pets", "flowers"], last_seen=16, pet_ages={ "Jack": 2, "Sunshine": 6 } ) ) ] # Initialize SparkSession spark = SparkSession.builder.master('local').appName("TinselQuickstart").getOrCreate() # Create DataFrame using the generated schema and data df = spark.createDataFrame(data=data, schema=spark_schema) df.printSchema() df.show(truncate=False) spark.stop()
Debug
Known issues
gotchaThe `tinsel` library has not seen updates since September 2018. While its core functionality remains valid, it might not be compatible with the absolute latest features or changes in very recent PySpark versions or Python language constructs.
fix
Thoroughly test `tinsel` generated schemas with your specific PySpark and Python versions. Consider manual schema definition for highly complex or cutting-edge PySpark features if issues arise.
affects: <=0.3.0
gotchaTinsel handles nullable fields and provides 'type shims' for certain Python types that don't have direct PySpark equivalents (e.g., `long` or `short`). Users should be aware of how these types are mapped to avoid unexpected schema interpretations.
fix
Review the generated PySpark schema (via `df.printSchema()`) carefully to confirm that types and nullability match expectations. Refer to the `tinsel` source for explicit type mapping details if ambiguities occur.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'tinsel'
The `tinsel` library is not installed in the current Python environment.
fix
Run `pip install tinsel` to install the library.
TypeError: 'StructType' object is not callable
Attempting to call the result of `transform(YourClass)` as if it were a function, or misusing the generated schema object.
fix
Ensure the output of `transform()` is assigned to a variable (e.g., `schema = transform(YourClass)`) and then passed to PySpark's `createDataFrame` using the `schema=` keyword argument (e.g., `spark.createDataFrame(data, schema=schema)`).
AttributeError: 'module' object has no attribute 'struct' or 'transform'
This usually means `struct` or `transform` was imported incorrectly, or the `tinsel` package itself is not properly installed or is shadowed by another module.
fix
Verify that `from tinsel import struct, transform` is used. Check your Python environment for any conflicting packages named `tinsel` or issues with the installation.
Upgrade
Version history
0.3.0latest on PyPI · released Sep 1, 2018
Audit
Dependencies
pysparkrequiredCore functionality relies on PySpark for DataFrame operations and schema generation.
dataclassesoptionalUsed for schema definition; built-in in Python 3.7+, requires backport for Python 3.6.
Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
tinsel — pip install tinsel · libregistry