# -*- coding: utf-8 -*-
from setuptools import setup

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

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

install_requires = \
['aiohttp',
 'attrs',
 'cattrs',
 'marshmallow>=3,<4',
 'mypy-extensions',
 'requests']

extras_require = \
{'pandas': ['pandas>=1']}

setup_kwargs = {
    'name': 'simple-smartsheet',
    'version': '0.5.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 some convenience features (for example, easy access to cells by column titles).  \n`simple-smartsheet` library is focused on the user experience in expense of feature coverage. \nAs of now, you can only interact with Sheets and Reports and their children objects (rows, columns, cells).  \nAdditionally, `simple-smartsheet` supports asyncio and provides both sync and async API at the same time.\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, ColumnType\n\nTOKEN = os.getenv("SMARTSHEET_API_TOKEN")\nSHEET_NAME = "[TEST] My New Sheet"\nsmartsheet = Smartsheet(TOKEN)\n\n# retrieve a list of sheets (limited set of attributes)\nsheets = smartsheet.sheets.list()\npprint(sheets)\n\n# delete the test sheet if already exists\nfor sheet in sheets:\n    if sheet.name == SHEET_NAME:\n        smartsheet.sheets.delete(id=sheet.id)\n\n# create a new Sheet\nnew_sheet_skeleton = Sheet(\n    name=SHEET_NAME,\n    columns=[\n        Column(primary=True, title="Full Name", type=ColumnType.TEXT_NUMBER),\n        Column(title="Number of read books", type=ColumnType.TEXT_NUMBER),\n        Column(title="Birth date", type=ColumnType.DATE),\n        Column(title="Library member", type=ColumnType.CHECKBOX),\n    ],\n)\n\n# print the sheet object attributes used by the Smartsheet API (camelCase)\npprint(new_sheet_skeleton.dump())\n\n# add the sheet via API\nresult = smartsheet.sheets.create(new_sheet_skeleton)\nsheet = result.obj\nprint(f"ID of the created sheet is {sheet.id!r}")\n\n# retrieve a sheet by name\n# this object is exactly the same as result.obj\nsheet = smartsheet.sheets.get(SHEET_NAME)\n\n# get 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# add rows (cells are created using different ways)\n# second way is the easiest\nnew_rows = [\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(\n            {"Full Name": "Bob Lee", "Number of read books": 2}\n        ),\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]\nsmartsheet.sheets.add_rows(sheet.id, new_rows)\n\n# sort rows by column "Full Name" descending / returns updated sheet\nsheet = smartsheet.sheets.sort_rows(\n    sheet, [{"column_title": "Full Name", "descending": True}]\n)\n\nprint("\\nSheet after adding rows:")\n# print a list of dictionaries containing column titles and values for each row\npprint(sheet.as_list())\n\n# get 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        updated_row = Row(\n            id=row.id, cells=[sheet.make_cell("Number of read books", 15)]\n        )\n        rows_to_update.append(updated_row)\n    elif full_name.startswith("Bob"):\n        row_id_to_delete = row.id  # used later\n\n# update rows\nsmartsheet.sheets.update_rows(sheet.id, rows_to_update)\n# or a single row\n# smartsheet.sheets.update_row(sheet.id, rows_to_update[0])\n\n# get an updated sheet\nsheet = smartsheet.sheets.get(id=sheet.id)\nprint("\\nSheet after updating rows:")\npprint(sheet.as_list())\n\n# delete a row\nsmartsheet.sheets.delete_row(sheet.id, row_id_to_delete)\n\n# get an updated sheet\nsheet = smartsheet.sheets.get(id=sheet.id)\nprint("\\nSheet after deleting rows:")\npprint(sheet.as_list())\n\n# delete a sheet by name\nsmartsheet.sheets.delete(SHEET_NAME)\nsheets = smartsheet.sheets.list()\npprint(sheets)\n```\n\n### API reference\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  * `sheets`: `simple_smartsheet.models.sheet.SheetCRUD` object which provides methods to interact with sheets\n  * `reports`: `simple_smartsheet.models.report.ReportCRUD` object which provides methods to interact with reports\n  \n#### Class `simple_smartsheet.models.sheet.SheetCRUD`\nMethods:\n  * `def get(name: Optional[str], id: Optional[int]) -> Sheet`: fetches Sheet by name or ID.\n  * `def list() -> List[Sheet]`: fetches a list of all sheets (summary only)\n  * `def create(obj: Sheet) -> Result`: adds a new sheet\n  * `def update(obj: Sheet) -> Result`: updates a sheet\n  * `def delete(name: Optional[str], id: Optional[int]) -> Result`: deletes a sheet by name or ID\n  * `def add_rows(sheet_id: int, rows: Sequence[Row]) -> Result`: adds rows to the sheet\n  * `def add_row(sheet_id: int, row: Row) -> Result`: add a single row to the sheet\n  * `def update_rows(sheet_id: int, rows: Sequence[Row]) -> Result`: updates several rows in the sheet\n  * `def update_row(sheet_id: int, row: Row) -> Result`: updates a single row\n  * `def delete_rows(sheet_id: int, row_ids: Sequence[int]) -> Result`: deletes several rows with provided ids\n  * `def delete_row(sheet_id: int, row_id: int) -> Result`: deletes a single row with a provided id\n  * `def sort_rows(sheet: Sheet, order: List[Dict[str, Any]]) -> Sheet`: 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\n#### Class `simple_smartsheet.models.sheet.AsyncSheetCRUD`\nThe methods listed below are asynchronous version of methods in `SheetCRUD`, listed for completeness:\n  * `async def get(name: Optional[str], id: Optional[int]) -> Sheet`\n  * `async def list() -> List[Sheet]`\n  * `async def create(obj: Sheet) -> Result`\n  * `async def update(obj: Sheet) -> Result`\n  * `async def delete(name: Optional[str], id: Optional[int]) -> Result`\n  * `async def add_rows(sheet_id: int, rows: Sequence[Row]) -> Result`\n  * `async def add_row(sheet_id: int, row: Row) -> Result`\n  * `async def update_rows(sheet_id: int, rows: Sequence[Row]) -> Result`\n  * `async def update_row(sheet_id: int, row: Row) -> Result`\n  * `async def delete_rows(sheet_id: int, row_ids: Sequence[int]) -> Result`\n  * `async def delete_row(sheet_id: int, row_id: int) -> Result`\n  * `async def sort_rows(sheet: Sheet, order: List[Dict[str, Any]]) -> Sheet`\n\n#### Class `simple_smartsheet.models.Sheet`\nAttributes (converted from camelCase to snake_case):\n  * <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]]) -> Optional[Row]`: 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]) -> List[Row]`: 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]) -> Column`: returns a Column object by column title or id\n  * `def build_index(indexes: List[IndexKeysDict]) -> None`: 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 make_cell(column_title: str, field_value: Union[float, str, datetime, None]) -> Cell`: creates a Cell object with provided column title and an associated value\n  * `def make_cells(fields: Dict[str, Union[float, str, datetime, None]]) -> List[Cell]`: creates a list of Cell objects from an input dictionary where column title is key associated with the field value\n  * `def as_list() -> List[Dict[str, Any]]`: 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>\n  * `rowNumber` is mapped to `num`\n  \nMethods:\n  * `def get_cell(column_title: Optional[str], column_id: Optional[int]) -> Cell` - returns a Cell object by column title (case-sensitive) or column id\n  * `def as_dict() -> Dict[str, Any]` - 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>\n\n#### Class `simple_smartsheet.models.cell.Cell`\nAttributes (converted from camelCase to snake_case):\n  * <http://smartsheet-platform.github.io/api-docs/#cells>\n\n#### Class `simple_smartsheet.models.extra.Result`:\nAttributes (converted from camelCase to snake_case):\n  * <https://smartsheet-platform.github.io/api-docs/#result-object>\n  * `result` attribute is renamed to `obj` to avoid confusion of calling `result.result`. `result` attribute is still available via property\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]]) -> ReportRow`: returns a ReportRow 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]) -> List[ReportRow]`: returns list of ReportRow objects by filter, if an index was built (see section "Custom Indexes")\n  * `def get_column(column_title: Optional[str], column_id: Optional[int]) -> ReportColumn`: returns a ReportColumn object by column title or id\n  * `def build_index(indexes: List[IndexKeysDict]) -> None`: 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() -> List[Dict[str, Any]]`: 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 sheets and reports. 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 snippet (see the full example in `examples/custom_indexes.py`):\n```python\nINDEXES = [\n    {"columns": ("Company",), "unique": False},\n    {"columns": ("Company", "Full Name"), "unique": True},\n    {"columns": ("Email address",), "unique": True},\n]\nsheet = smartsheet.sheets.get("[TEST] Index Sheet")\nsheet.build_index(INDEXES)\n\nprint("\\nRow where email address is \'charlie.brown@globex.com\':")\nprint(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("\\nRows where the company name is \'ACME\':")\nprint([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``` \n\n### Asyncio\nThe library supports asyncio for all i/o methods, instead of calling:\n```\nsmartsheet = Smartsheet(token)\nsheet = smartsheets.sheets.get(\'my-sheet\')\n```  \nyou need to call asynchronous context manager with an async version of smartsheet class:\n```\nwith AsyncSmartsheet(token) as smartsheet:\n   sheet = await smartsheet.sheets.get(\'my-sheet\')\n```\n\nA complete asyncio example with different operations on sheets and reports can be found in `examples/async.py`\n\n### Pandas\nIf pandas is installed (either separately or as extras `pip install simple-smartsheet[pandas]`), sheets and rows can be exported as `pandas.DataFrame` or `pandas.Series` respectively. Besides column titles and respective values from the sheet, they will also include row IDs and row numbers\n```\nsheet = smartsheets.sheets.get(\'my-sheet\')\ndf = sheet.as_dataframe()\nseries = sheet.rows[0].as_series()\n```  \n',
    'author': 'Dmitry Figol',
    'author_email': 'git@dmfigol.me',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/dmfigol/simple-smartsheet',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'extras_require': extras_require,
    'python_requires': '>=3.6.1',
}


setup(**setup_kwargs)
