Metadata-Version: 2.5
Name: typespark
Version: 2.0.0a1
Summary: Bringing classes to PySpark DataFrames, built on attrs
Project-URL: Documentation, https://typespark.dev/
Project-URL: Repository, https://github.com/eageby/typespark
Project-URL: Issues, https://github.com/eageby/typespark/issues
Author-email: Elias Ågeby <elias.ageby@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: attrs,dataclass,dataframe,model,pyspark,schema,spark,type-safety,typing
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Database
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: <4,>=3.12
Requires-Dist: attrs<26,>=25.1.0
Requires-Dist: simple-parsing<0.2,>=0.1.7
Requires-Dist: typing-extensions>=4.15.0
Provides-Extra: pyspark
Requires-Dist: pyspark<4.4,>=3.5.2; (python_version < '3.14') and extra == 'pyspark'
Requires-Dist: pyspark<4.4,>=4.0; (python_version >= '3.14') and extra == 'pyspark'
Description-Content-Type: text/markdown

# TypeSpark

<!-- --8<-- [start:intro] -->
**Bringing classes to PySpark DataFrames, built on [attrs](https://www.attrs.org/).**

Declare a DataFrame like a dataclass: each attribute is a typed column. Wrap a Spark
DataFrame in the class and you get autocomplete, checked column access and transforms your type
checker can verify, with no `.alias()` boilerplate. Every operation calls PySpark
directly, so Spark runs exactly the code you'd have written.

```python
import typespark as ts
import typespark.functions as tsf


class Person(ts.DataFrame):
    name: ts.String
    age: ts.Int


class Adult(ts.DataFrame):
    full_name: ts.String
    can_vote: ts.Bool


def adults(people: Person) -> Adult:
    return Adult(
        people,
        full_name=tsf.initcap(people.name),  # a typed String
        can_vote=people.age >= 18,  # aliased to "can_vote"
    )
```

- **Familiar syntax.** If you've written a dataclass or an attrs class, you can write a
  model: annotations, defaults, `field(...)`, inheritance.
- **Typed functions.** `typespark.functions` mirrors `pyspark.sql.functions` with typed
  arguments and results: `tsf.upper` on a number, or a misspelled unit in `tsf.date_trunc`,
  is a type error instead of a silent cast or `null`.
- **Columns are symbols, not strings.** Go to definition, find references and rename work
  on `people.age` like on any Python attribute.
- **Mistakes show up in your editor.** A misspelled column, a missing output column or a
  wrong type is a type error, not a failure when Spark runs.
- **No `.alias()`.** Each keyword is aliased to its column name, and `adults` returns a
  typed `Adult`, not a bare `DataFrame`.
- **One schema.** The class types your code and generates the `StructType` for your tables.
<!-- --8<-- [end:intro] -->

## Installation

<!-- --8<-- [start:install] -->
```bash
pip install "typespark[pyspark]"   # with PySpark
pip install typespark              # PySpark already provided by your environment
```

Python 3.12+, PySpark 3.5 to 4.3. Type checking with pyright (Pylance) or mypy.

**TypeSpark 2.0 is in pre-release:** add `--pre` to install it. Without it, pip installs 1.x.
<!-- --8<-- [end:install] -->

## Documentation

**<https://typespark.dev/>**

- [Why TypeSpark](https://typespark.dev/why/): side by side with plain
  PySpark
- [Concepts](https://typespark.dev/concepts/models/): models, columns,
  transforms, aggregates, ...
- [Migrating from 1.x](https://typespark.dev/migration/)
- [Contributing](https://typespark.dev/contributing/)

## License

[MIT](LICENSE)
