# -*- coding: utf-8 -*-
from distutils.core import setup

packages = \
['simple_smartsheet', 'simple_smartsheet.models']

package_data = \
{'': ['*']}

install_requires = \
['attrs',
 'cattrs',
 'marshmallow>=3.0.0rc1,<4.0.0',
 'mypy-extensions',
 'requests']

setup_kwargs = {
    'name': 'simple-smartsheet',
    'version': '0.2.0',
    'description': 'Python library to interact with Smartsheet API',
    'long_description': '## Simple Smartsheet\nPython library to interact with Smartsheet API easily\n\n### Installation\nRequires Python 3.6+  \n`pip install simple-smartsheet`\n\n### Why not smartsheet-python-sdk\n`smartsheet-python-sdk` has very wide object coverage and maps to Smartsheet API very nicely, but it does not have any additional features (for example, easy access to cells by column titles).  \n`simple-smartsheet` library is focused on user experience first in expense of feature coverage. \nAs of now, you can only interact with Sheets and Reports and their children objects (rows, columns, cells). For reports Smartsheet API provides read-only access.\n\n### Usage\n```python\nimport os\nfrom datetime import date\nfrom pprint import pprint\n\nfrom simple_smartsheet import Smartsheet\nfrom simple_smartsheet.models import Sheet, Column, Row, Cell\n\nTOKEN = os.getenv("SMARTSHEET_API_TOKEN")\nsmartsheet = Smartsheet(TOKEN)\n\n# getting a simplified view of sheets\nsheets = smartsheet.sheets.list()\npprint(sheets)\n\nsheet_name = "My New Sheet"\n# Delete the test sheet if already exists\nfor sheet in sheets:\n    if sheet.name == sheet_name:\n        smartsheet.sheets.delete(sheet_name)\n\n# creating new Sheet\nnew_sheet = Sheet(\n    name=sheet_name,\n    columns=[\n        Column(primary=True, title="Full Name", type="TEXT_NUMBER"),\n        Column(title="Number of read books", type="TEXT_NUMBER"),\n        Column(title="Birth date", type="DATE"),\n        Column(title="Library member", type="CHECKBOX"),\n    ],\n)\n\n# print the sheet object as a dictionary which will be used in REST API\npprint(new_sheet.dump())\n\n# adding the sheet via API\nsmartsheet.sheets.create(new_sheet)\n\n# getting a simplified view of sheets\nsheets = smartsheet.sheets.list()\npprint(sheets)\n\n# getting the sheet by name\nsheet = smartsheet.sheets.get("My New Sheet")\n\n# printing the sheet object attributes\npprint(sheet.__dict__)\n# or printing the sheet object as a dictionary which will be used in REST API\npprint(sheet.dump())\n\n# getting columns details by column title (case-sensitive)\nfull_name_column = sheet.get_column("Full Name")\npprint(full_name_column.__dict__)\nnum_books_column = sheet.get_column("Number of read books")\npprint(num_books_column.__dict__)\n\n# adding rows (cells created using different ways):\nsheet.add_rows(\n    [\n        Row(\n            to_top=True,\n            cells=[\n                Cell(column_id=full_name_column.id, value="Alice Smith"),\n                Cell(column_id=num_books_column.id, value=5),\n            ],\n        ),\n        Row(\n            to_top=True,\n            cells=sheet.make_cells({"Full Name": "Bob Lee", "Number of read books": 2}),\n        ),\n        Row(\n            to_top=True,\n            cells=[\n                sheet.make_cell("Full Name", "Charlie Brown"),\n                sheet.make_cell("Number of read books", 1),\n                sheet.make_cell("Birth date", date(1990, 1, 1)),\n            ],\n        ),\n    ]\n)\n\n# sort rows now by column "Full Name" descending / returns updated sheet\nsheet = sheet.sort_rows([{"column_title": "Full Name", "descending": True}])\n\n# or getting an updated sheet again\n# sheet = smartsheet.sheets.get("My New Sheet")\nprint("\\nSheet after adding rows:")\n# all sheet attributes\npprint(sheet.__dict__)\n# or just a list of dictionaries containing column titles and values\npprint(sheet.as_list())\n\n# getting a specific cell and updating it:\nrow_id_to_delete = None\nrows_to_update = []\nfor row in sheet.rows:\n    full_name = row.get_cell("Full Name").value\n    num_books = row.get_cell("Number of read books").value\n    print(f"{full_name} has read {num_books} books")\n    if full_name.startswith("Charlie"):\n        num_books_cell = row.get_cell("Number of read books")\n        num_books_cell.value += 1\n        rows_to_update.append(row)\n    elif full_name.startswith("Bob"):\n        row_id_to_delete = row.id  # used later\n\n# update rows\nsheet.update_rows(rows_to_update)\n# or a single row\n# sheet.update_rows(rows_to_update[0])\n\n# getting an updated sheet\nsheet = smartsheet.sheets.get("My New Sheet")\nprint("\\nSheet after updating rows:")\npprint(sheet.as_list())\n\n# deleting row by id\nsheet.delete_row(row_id_to_delete)\n\n# getting an updated sheet\nsheet = smartsheet.sheets.get("My New Sheet")\nprint("\\nSheet after deleting rows:")\npprint(sheet.as_list())\n\n# deleting Sheet\nsheet = smartsheet.sheets.delete("My New Sheet")\nsheets = smartsheet.sheets.list()\npprint(sheets)\n```\n\n### Docs\nWhile a separate docs page is work in progress, available public API is described here\n#### Class `simple_smartsheet.Smartsheet`\nThis class a main entry point for the library  \nMethods:\n  * `def __init__(token: str)`: constructor for the class\n  \nAttributes:\n  * `token`: Smartsheet API token, obtained in Personal Settings -> API access\n  * `session`: requests.Session object which stores headers based on the token\n  * `sheets`: `simple_smartsheet.models.sheet.SheetsCRUD` object which provides methods to interact with Sheets\n  \n#### Class `simple_smartsheet.models.sheet.SheetsCRUD`\nMethods:\n  * `def get(name: Optional[str], id: Optional[int], index_keys: Optional[Dict[str, Any]])`: fetches Sheet by name or ID. It can also build an index for several fields to do quick rows lookup (see section "Custom Indexes")\n  * `def list()`: fetches a list of all sheets (summary only)\n  * `def create(obj: Sheet)`: adds a new sheet\n  * `def update(obj: Sheet)`: updates a sheet\n  * `def delete(name: Optional[str], id: Optional[int])`: deletes a sheet by name or ID\n\n#### Class `simple_smartsheet.models.Sheet`\nAttributes (converted from camelCase to snake_case):\n  * [http://smartsheet-platform.github.io/api-docs/#sheets](http://smartsheet-platform.github.io/api-docs/#sheets)\n  \nMethods:\n  * `def get_row(row_num: Optional[int], row_id: Optional[int], filter: Optional[Dict[str, Any]])`: returns a Row object by row number, ID or by filter, if a unique index was built (see section "Custom Indexes")\n  * `def get_rows(index_query: Dict[str, Any])`: returns list of Row objects by filter, if an index was built (see section "Custom Indexes")\n  * `def get_column(column_title: Optional[str], column_id: Optional[int])`: returns a Column object by column title or id\n  * `def add_rows(rows: Sequence[Row])`: adds rows to the sheet\n  * `def add_row(row: Row)`: add a single row to the sheet\n  * `def update_rows(rows: Sequence[Row])`: updates several rows in the sheet\n  * `def update_row(row: Row)`: updates a single row\n  * `def delete_rows(row_ids: Sequence[int])`: delete several rows with provided ids\n  * `def delete_row(row_id: int)`: delete a single row with a provided id\n  * `def build_index(indexes: List[IndexKeysDict])`: builds one or more indexes for quick row lookup using `get_row` or `get_rows`, e.g.:  \n```\nsheet.build_index([\n    {"columns": ("Company Name",), "unique": False},\n    {"columns": ("Company Name", "Full Name"), "unique": True}\n])\n```  \n  * `def sort_rows(order: List[Dict[str, Any]])`: sorts sheet rows with the specified order, e.g.:   \n```\nsheet.sort_rows([\n    {"column_title": "Birth date", "descending": True},\n    {"column_title": "Full Name"}\n])\n```\n  * `def make_cell(column_title: str, field_value: Union[float, str, datetime, None])`: creates a Cell object with provided column title and an associated value\n  * `def make_cells(fields: Dict[str, Union[float, str, datetime, None]])`: creates a list of Cell objects from an input dictionary where column title is key associated with the field value\n  * `def as_list()`: returns a list of dictionaries where column title is key associated with the field value\n  \n#### Class `simple_smartsheet.models.row.Row`\nAttributes (converted from camelCase to snake_case):\n  * [http://smartsheet-platform.github.io/api-docs/#rows](http://smartsheet-platform.github.io/api-docs/#rows)\n  * `rowNumber` is mapped to `num`\n  \nMethods:\n  * `def get_cell(column_title: Optional[str], column_id: Optional[int])` - returns a Cell object by column title (case-sensitive) or column id\n  * `def as_dict()` - returns a dictionary of column title to cell value mappings\n\n#### Class `simple_smartsheet.models.column.Column`\nAttributes (converted from camelCase to snake_case):\n  * [http://smartsheet-platform.github.io/api-docs/#columns](http://smartsheet-platform.github.io/api-docs/#columns)\n\n#### Class `simple_smartsheet.models.cell.Cell`\nAttributes (converted from camelCase to snake_case):\n  * [http://smartsheet-platform.github.io/api-docs/#cells](http://smartsheet-platform.github.io/api-docs/#cells)\n\n#### Class `simple_smartsheet.models.Report`\nAttributes (converted from camelCase to snake_case):\n  * [http://smartsheet-platform.github.io/api-docs/#reports](http://smartsheet-platform.github.io/api-docs/#reports)\n  \nImplements the following Sheet methods:\n  * `def get_row(row_num: Optional[int], row_id: Optional[int], filter: Optional[Dict[str, Any]])`: returns a Row object by row number, ID or by filter, if a unique index was built (see section "Custom Indexes")\n  * `def get_rows(index_query: Dict[str, Any])`: returns list of Row objects by filter, if an index was built (see section "Custom Indexes")\n  * `def get_column(column_title: Optional[str], column_id: Optional[int])`: returns a Column object by column title or id\n  * `def build_index(indexes: List[IndexKeysDict])`: builds one or more indexes for quick row lookup using `get_row` or `get_rows`, e.g.:  \n```\nsheet.build_index([\n    {"columns": ("Company Name",), "unique": False},\n    {"columns": ("Company Name", "Full Name"), "unique": True}\n])\n```  \n  * `def as_list()`: returns a list of dictionaries where column title is key associated with the field value\n  \n### Custom Indexes\nIt is possible to build indexes to enable quick rows lookups. For this, after retrieving the sheet, call `sheet.build_index` function. It takes only one argument: a list of dictionaries, where every dictionary has two keys `columns` and `unique`. `columns` should contain a tuple with column titles (case sensitive). `unique` controls if the index always points to a single row (value `True`, lookups are done using `get_row` method) or multiple rows (value `False`, lookups are done using `get_rows` method).\n\nBelow you can find a code example:\n```python\nimport os\n\nfrom simple_smartsheet import Smartsheet\n\nfrom pprint import pprint\n\nTOKEN = os.getenv("SMARTSHEET_API_TOKEN")\nsmartsheet = Smartsheet(TOKEN)\n\nINDEXES = [\n    {"columns": ("Company Name",), "unique": False},\n    {"columns": ("Company Name", "Full Name"), "unique": True},\n    {"columns": ("Email Address",), "unique": True},\n]\nsheet = smartsheet.sheets.get("Index Test Sheet")\nsheet.build_index(INDEXES)\n\npprint(sheet.indexes)\n# >\n# defaultdict(<class \'dict\'>,\n#             {(\'Company Name\',): {(\'ACME\',): [Row(id=525791232583556, num=1),\n#                                              Row(id=5029390859954052, num=2)],\n#                                  (\'Globex\',): [Row(id=2777591046268804, num=3)]},\n#              (\'Company Name\', \'Full Name\'): {(\'ACME\', \'Alice Smith\'): Row(id=525791232583556, num=1),\n#                                              (\'ACME\', \'Bob Lee\'): Row(id=5029390859954052, num=2),\n#                                              (\'Globex\', \'Charlie Brown\'): Row(id=2777591046268804, num=3)},\n#              (\'Email Address\',): {(\'alice.smith@acme.com\',): Row(id=525791232583556, num=1),\n#                                   (\'bob.lee@acme.com\',): Row(id=5029390859954052, num=2),\n#                                   (\'charlie.brown@globex.com\',): Row(id=2777591046268804, num=3)}})\n\npprint(sheet.as_list())\n# >\n# [{\'Company Name\': \'ACME\',\n#   \'Email Address\': \'alice.smith@acme.com\',\n#   \'Full Name\': \'Alice Smith\'},\n#  {\'Company Name\': \'ACME\',\n#   \'Email Address\': \'bob.lee@acme.com\',\n#   \'Full Name\': \'Bob Lee\'},\n#  {\'Company Name\': \'Globex\',\n#   \'Email Address\': \'charlie.brown@globex.com\',\n#   \'Full Name\': \'Charlie Brown\'}]\n\nprint("\\nRow where email address is \'charlie.brown@globex.com\':")\npprint(sheet.get_row(filter={"Email Address": "charlie.brown@globex.com"}).as_dict())\n# >\n# {\'Company Name\': \'Globex\',\n#  \'Email Address\': \'charlie.brown@globex.com\',\n#  \'Full Name\': \'Charlie Brown\'}\n\nprint("\\nRow where full name is \'Alice Smith\' and the company name is \'ACME\':")\npprint(\n    sheet.get_row(filter={"Full Name": "Alice Smith", "Company Name": "ACME"}).as_dict()\n)\n# >\n# {\'Company Name\': \'ACME\',\n#  \'Email Address\': \'alice.smith@acme.com\',\n#  \'Full Name\': \'Alice Smith\'}\n\nprint("\\nRows where the company name is \'ACME\':")\npprint([row.as_dict() for row in sheet.get_rows(filter={"Company Name": "ACME"})])\n# >\n# [{\'Company Name\': \'ACME\',\n#   \'Email Address\': \'alice.smith@acme.com\',\n#   \'Full Name\': \'Alice Smith\'},\n#  {\'Company Name\': \'ACME\',\n#   \'Email Address\': \'bob.lee@acme.com\',\n#   \'Full Name\': \'Bob Lee\'}]\n``` ',
    'author': 'Dmitry Figol',
    'author_email': 'git@dmfigol.me',
    'url': 'https://github.com/dmfigol/simple-smartsheet',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.6',
}


setup(**setup_kwargs)
