Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ezwelty/tablecloth
Spreadsheet templates for tabular data entry
https://github.com/ezwelty/tablecloth
Last synced: 9 days ago
JSON representation
Spreadsheet templates for tabular data entry
- Host: GitHub
- URL: https://github.com/ezwelty/tablecloth
- Owner: ezwelty
- License: mit
- Created: 2023-02-23T13:44:29.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-18T11:28:21.000Z (3 months ago)
- Last Synced: 2024-09-18T12:08:52.453Z (3 months ago)
- Language: Python
- Size: 1.03 MB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- jimsghstars - ezwelty/tablecloth - Spreadsheet templates for tabular data entry (Python)
README
`tablecloth`: Spreadsheet templates for tabular data entry
============[![codecov](https://codecov.io/gh/ezwelty/tablecloth/branch/main/graph/badge.svg?token=RP9E7WLFCI)](https://codecov.io/gh/ezwelty/tablecloth)
[![tests](https://github.com/ezwelty/tablecloth/actions/workflows/tests.yaml/badge.svg)](https://github.com/ezwelty/tablecloth/actions/workflows/tests.yaml)![A Google Sheets template in action](docs/_static/example.png?raw=true)
_Google Sheets template generated for [tests/datapackage.yaml](tests/datapackage.yaml) with invalid values highlighted in red._## Installation
```sh
pip install "tablecloth[excel,gsheets] @ git+https://github.com/ezwelty/tablecloth"
```* `[excel]`: Adds (optional) support for Microsoft Excel
* `[gsheets]`: Adds (optional) support for Google Sheets## Usage
```py
import tablecloth.excel# Load a Frictionless Tabular Data Package specification
package = {
'name': 'package',
'resources': [{
'name': 'main',
'schema': {
'fields': [{
'name': 'id',
'description': 'Any positive integer',
'type': 'integer',
'constraints': {'required': True, 'unique': True, 'minimum': 1},
}, {
'name': 'number_minmax',
'description': 'A number in interval [1, 10]',
'type': 'number',
'constraints': {'minimum': 1, 'maximum': 10},
}, {
'name': 'boolean',
'description': 'Any boolean',
'type': 'boolean',
}, {
'name': 'string_minmax',
'description': 'Any string with length between 2 and 3',
'type': 'string',
'constraints': {'minLength': 2, 'maxLength': 3},
}, {
'name': 'string_enum',
'description': 'One of the first three letters of the alphabet',
'type': 'string',
'constraints': {'enum': ['a', 'b', 'c']},
}]
}
}, {
'name': 'secondary',
'schema': {
'foreignKeys': [{
'fields': ['main_id'],
'reference': {'resource': 'main', 'fields': ['id']},
}],
'fields': [{
'name': 'main_id',
'description': 'Any value in main.id',
'type': 'integer',
}]
}
}]
}# Use field descriptions as header comments
comments = {
resource['name']: [
field['description'] for field in resource['schema']['fields']
] for resource in package['resources']
}# Build Excel template
tablecloth.excel.write_template(
package, path='template.xlsx', header_comments=comments
)
```## Development
Clone the repository, use `poetry` to install `tablecloth` and all its dependencies
into a Python virtual environment, and run (most) tests:```bash
git clone https://github.com/ezwelty/tablecloth
cd tablecloth
poetry install --all-extras
poetry run pytest --doctest-modules src tests
```Consider installing [`pre-commit`](https://pre-commit.com) (if needed)
and installing the hooks:```bash
pre-commit install
```### Google Sheets
Running tests for Google Sheets requires a JSON key for a Google Cloud project service
account (https://pygsheets.readthedocs.io/en/stable/authorization.html#service-account).
Copy the example environment file:```bash
cp .env.example .env
```and fill in the content of your JSON key.
Optionally, add your Google account email so that Google Sheets created by your
service account are shared with you.
Once configured, use the `--gsheets` flag to include Google Sheets tests:```bash
poetry run pytest --doctest-modules src tests --gsheets
```