Name | codaio JSON |
Version |
0.6.12
JSON |
| download |
home_page | https://github.com/Blasterai/codaio |
Summary | Python wrapper for Coda.io API |
upload_time | 2024-05-08 08:57:43 |
maintainer | None |
docs_url | None |
author | MB |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[](https://vshymanskyy.github.io/StandWithUkraine)
## Python wrapper for [Coda.io](https://coda.io) API
[](https://coda.io/developers/apis/v1beta1)

[](https://github.com/psf/black)
[](https://codaio.readthedocs.io/en/latest/?badge=latest)
[](https://pypi.org/project/codaio/)

[](https://www.buymeacoffee.com/licht1stein)
Don't hesitate to contribute, issues and PRs very welcome!
### Installation
Install with [poetry](https://python-poetry.org/) (always recommended):
```shell script
poetry add codaio
```
or with `pip`
```shell script
pip install codaio
```
### Config via environment variables
The following variables will be called from environment where applicable:
* `CODA_API_ENDPOINT` (default value `https://coda.io/apis/v1`)
* `CODA_API_KEY` - your API key to use when initializing client from environment
### Quickstart using raw API
Coda class provides a wrapper for all API methods. If API response included a JSON it will be returned as a dictionary from all methods. If it didn't a dictionary `{"status": response.status_code}` will be returned.
If request wasn't successful a `CodaError` will be raised with details of the API error.
```python
from codaio import Coda
coda = Coda('YOUR_API_KEY')
>>> coda.create_doc('My Document')
{'id': 'NEW_DOC_ID', 'type': 'doc', 'href': 'https://coda.io/apis/v1/docs/NEW_DOC_ID', 'browserLink': 'https://coda.io/d/_dNEW_DOC_ID', 'name': 'My Document', 'owner': 'your@email', 'ownerName': 'Your Name', 'createdAt': '2020-09-28T19:32:20.866Z', 'updatedAt': '2020-09-28T19:32:20.924Z'}
```
For full API reference for Coda class see [documentation](https://codaio.readthedocs.io/en/latest/index.html#codaio.Coda)
### Quickstart using codaio objects
`codaio` implements convenient classes to work with Coda documents: `Document`, `Table`, `Row`, `Column` and `Cell`.
```python
from codaio import Coda, Document
# Initialize by providing a coda object directly
coda = Coda('YOUR_API_KEY')
doc = Document('YOUR_DOC_ID', coda=coda)
# Or initialiaze from environment by storing your API key in environment variable `CODA_API_KEY`
doc = Document.from_environment('YOUR_DOC_ID')
doc.list_tables()
table = doc.get_table('TABLE_ID')
```
#### Fetching a Row
```python
# You can fetch a row by ID
row = table['ROW_ID']
```
#### Using with Pandas
If you want to load a codaio Table or Row into pandas, you can use the `Table.to_dict()` or `Row.to_dict()` methods:
```python
import pandas as pd
df = pd.DataFrame(table.to_dict())
```
#### Fetching a Cell
```python
# Or fetch a cell by ROW_ID and COLUMN_ID
cell = table['ROW_ID']['COLUMN_ID']
# This is equivalent to getting item from a row
cell = row['COLUMN_ID']
# or
cell = row['COLUMN_NAME'] # This should work fine if COLUMN_NAME is unique, otherwise it will raise AmbiguousColumn error
# or use a Column instance
cell = row[column]
```
#### Changing Cell value
```python
row['COLUMN_ID'] = 'foo'
# or
row['Column Name'] = 'foo'
```
#### Iterating over rows
```python
# Iterate over rows using IDs -> delete rows that match a condition
for row in table.rows():
if row['COLUMN_ID'] == 'foo':
row.delete()
# Iterate over rows using names -> edit cells in rows that match a condition
for row in table.rows():
if row['Name'] == 'bar':
row['Value'] = 'spam'
```
#### Upserting new row
To upsert a new row you can pass a list of cells to `table.upsert_row()`
```python
name_cell = Cell(column='COLUMN_ID', value_storage='new_name')
value_cell = Cell(column='COLUMN_ID', value_storage='new_value')
table.upsert_row([name_cell, value_cell])
```
#### Upserting multiple new rows
Works like upserting one row, except you pass a list of lists to `table.upsert_rows()` (rows, not row)
```python
name_cell_a = Cell(column='COLUMN_ID', value_storage='new_name')
value_cell_a = Cell(column='COLUMN_ID', value_storage='new_value')
name_cell_b = Cell(column='COLUMN_ID', value_storage='new_name')
value_cell_b = Cell(column='COLUMN_ID', value_storage='new_value')
table.upsert_rows([[name_cell_a, value_cell_a], [name_cell_b, value_cell_b]])
```
#### Updating a row
To update a row use `table.update_row(row, cells)`
```python
row = table['ROW_ID']
name_cell_a = Cell(column='COLUMN_ID', value_storage='new_name')
value_cell_a = Cell(column='COLUMN_ID', value_storage='new_value')
table.update_row(row, [name_cell_a, value_cell_a])
```
### Documentation
`codaio` documentation lives at [readthedocs.io](https://codaio.readthedocs.io/en/latest/index.html)
### Running the tests
The recommended way of running the test suite is to use [nox](https://nox.thea.codes/en/stable/tutorial.html).
Once `nox`: is installed, just run the following command:
```shell script
nox
```
The nox session will run the test suite against python 3.8 and 3.7. It will also look for linting errors with `flake8`.
You can still invoke `pytest` directly with:
```shell script
poetry run pytest --cov
```
Check out the fixtures if you want to improve the testing process.
#### Contributing
If you are willing to contribute please go ahead, we can use some help!
##### Using CI to deploy to PyPi
When a PR is merged to master the CI will try to deploy to pypi.org using poetry. It will succeed only if the
version number changed in pyproject.toml.
To do so use poetry's [version command](https://python-poetry.org/docs/cli/#version). For example:
Bump 0.4.11 to 0.4.12:
```bash
poetry version patch
```
Bump 0.4.11 to 0.5.0:
```bash
poetry version minor
```
Bump 0.4.11 to 1.0.0:
```bash
poetry version major
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Blasterai/codaio",
"name": "codaio",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "MB",
"author_email": "mb@blaster.ai",
"download_url": "https://files.pythonhosted.org/packages/f4/d3/36f172b0f89aaf35bd51ab7f8ce48690d726b74f4db37e0644f96d751a61/codaio-0.6.12.tar.gz",
"platform": null,
"description": "[](https://vshymanskyy.github.io/StandWithUkraine)\n\n## Python wrapper for [Coda.io](https://coda.io) API\n\n[](https://coda.io/developers/apis/v1beta1)\n\n[](https://github.com/psf/black)\n[](https://codaio.readthedocs.io/en/latest/?badge=latest)\n[](https://pypi.org/project/codaio/)\n\n[](https://www.buymeacoffee.com/licht1stein)\n\nDon't hesitate to contribute, issues and PRs very welcome! \n\n\n### Installation\nInstall with [poetry](https://python-poetry.org/) (always recommended):\n\n```shell script\npoetry add codaio\n```\n\nor with `pip`\n\n```shell script\npip install codaio\n```\n\n### Config via environment variables\nThe following variables will be called from environment where applicable:\n\n* `CODA_API_ENDPOINT` (default value `https://coda.io/apis/v1`)\n* `CODA_API_KEY` - your API key to use when initializing client from environment\n\n### Quickstart using raw API\nCoda class provides a wrapper for all API methods. If API response included a JSON it will be returned as a dictionary from all methods. If it didn't a dictionary `{\"status\": response.status_code}` will be returned.\nIf request wasn't successful a `CodaError` will be raised with details of the API error.\n\n```python\nfrom codaio import Coda\n\ncoda = Coda('YOUR_API_KEY')\n\n>>> coda.create_doc('My Document')\n{'id': 'NEW_DOC_ID', 'type': 'doc', 'href': 'https://coda.io/apis/v1/docs/NEW_DOC_ID', 'browserLink': 'https://coda.io/d/_dNEW_DOC_ID', 'name': 'My Document', 'owner': 'your@email', 'ownerName': 'Your Name', 'createdAt': '2020-09-28T19:32:20.866Z', 'updatedAt': '2020-09-28T19:32:20.924Z'}\n```\nFor full API reference for Coda class see [documentation](https://codaio.readthedocs.io/en/latest/index.html#codaio.Coda)\n\n### Quickstart using codaio objects\n\n`codaio` implements convenient classes to work with Coda documents: `Document`, `Table`, `Row`, `Column` and `Cell`.\n\n```python\nfrom codaio import Coda, Document\n\n# Initialize by providing a coda object directly\ncoda = Coda('YOUR_API_KEY')\n\ndoc = Document('YOUR_DOC_ID', coda=coda)\n\n# Or initialiaze from environment by storing your API key in environment variable `CODA_API_KEY`\ndoc = Document.from_environment('YOUR_DOC_ID')\n\ndoc.list_tables()\n\ntable = doc.get_table('TABLE_ID')\n```\n#### Fetching a Row\n```python\n# You can fetch a row by ID\nrow = table['ROW_ID']\n```\n\n#### Using with Pandas\nIf you want to load a codaio Table or Row into pandas, you can use the `Table.to_dict()` or `Row.to_dict()` methods:\n```python\nimport pandas as pd\n\ndf = pd.DataFrame(table.to_dict())\n```\n\n#### Fetching a Cell\n```python\n# Or fetch a cell by ROW_ID and COLUMN_ID\ncell = table['ROW_ID']['COLUMN_ID'] \n\n# This is equivalent to getting item from a row\ncell = row['COLUMN_ID']\n# or \ncell = row['COLUMN_NAME'] # This should work fine if COLUMN_NAME is unique, otherwise it will raise AmbiguousColumn error\n# or use a Column instance\ncell = row[column]\n```\n\n#### Changing Cell value\n\n```python\nrow['COLUMN_ID'] = 'foo'\n# or\nrow['Column Name'] = 'foo'\n```\n\n#### Iterating over rows\n```python\n# Iterate over rows using IDs -> delete rows that match a condition\nfor row in table.rows():\n if row['COLUMN_ID'] == 'foo':\n row.delete()\n\n# Iterate over rows using names -> edit cells in rows that match a condition\nfor row in table.rows():\n if row['Name'] == 'bar':\n row['Value'] = 'spam'\n```\n\n#### Upserting new row\nTo upsert a new row you can pass a list of cells to `table.upsert_row()`\n```python\nname_cell = Cell(column='COLUMN_ID', value_storage='new_name')\nvalue_cell = Cell(column='COLUMN_ID', value_storage='new_value')\n\ntable.upsert_row([name_cell, value_cell])\n```\n\n#### Upserting multiple new rows\nWorks like upserting one row, except you pass a list of lists to `table.upsert_rows()` (rows, not row)\n```python\nname_cell_a = Cell(column='COLUMN_ID', value_storage='new_name')\nvalue_cell_a = Cell(column='COLUMN_ID', value_storage='new_value')\n\nname_cell_b = Cell(column='COLUMN_ID', value_storage='new_name')\nvalue_cell_b = Cell(column='COLUMN_ID', value_storage='new_value')\n\ntable.upsert_rows([[name_cell_a, value_cell_a], [name_cell_b, value_cell_b]])\n```\n\n#### Updating a row\nTo update a row use `table.update_row(row, cells)`\n```python\nrow = table['ROW_ID']\n\nname_cell_a = Cell(column='COLUMN_ID', value_storage='new_name')\nvalue_cell_a = Cell(column='COLUMN_ID', value_storage='new_value')\n\ntable.update_row(row, [name_cell_a, value_cell_a])\n```\n\n### Documentation\n\n`codaio` documentation lives at [readthedocs.io](https://codaio.readthedocs.io/en/latest/index.html)\n\n### Running the tests\n\nThe recommended way of running the test suite is to use [nox](https://nox.thea.codes/en/stable/tutorial.html).\n\nOnce `nox`: is installed, just run the following command:\n```shell script\nnox\n```\n\nThe nox session will run the test suite against python 3.8 and 3.7. It will also look for linting errors with `flake8`.\n\nYou can still invoke `pytest` directly with:\n```shell script\npoetry run pytest --cov\n```\n\nCheck out the fixtures if you want to improve the testing process.\n\n\n#### Contributing\n\nIf you are willing to contribute please go ahead, we can use some help!\n\n##### Using CI to deploy to PyPi\n\nWhen a PR is merged to master the CI will try to deploy to pypi.org using poetry. It will succeed only if the \nversion number changed in pyproject.toml. \n\nTo do so use poetry's [version command](https://python-poetry.org/docs/cli/#version). For example:\n\nBump 0.4.11 to 0.4.12:\n```bash\npoetry version patch\n```\n\nBump 0.4.11 to 0.5.0:\n```bash\npoetry version minor\n```\n\nBump 0.4.11 to 1.0.0:\n```bash\npoetry version major\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python wrapper for Coda.io API",
"version": "0.6.12",
"project_urls": {
"Documentation": "https://codaio.readthedocs.io/en/latest/index.html",
"Homepage": "https://github.com/Blasterai/codaio"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6992988eb56861c339b0a526b9c171b5208500400feca8effc5f133f5fe35245",
"md5": "e47e6185038b5761460d991df3f2da19",
"sha256": "34f60fc755e1562b0a88e825a2aaa1ea21b952535ea9254a25047ec3490ba4d8"
},
"downloads": -1,
"filename": "codaio-0.6.12-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e47e6185038b5761460d991df3f2da19",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 18544,
"upload_time": "2024-05-08T08:57:41",
"upload_time_iso_8601": "2024-05-08T08:57:41.778115Z",
"url": "https://files.pythonhosted.org/packages/69/92/988eb56861c339b0a526b9c171b5208500400feca8effc5f133f5fe35245/codaio-0.6.12-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f4d336f172b0f89aaf35bd51ab7f8ce48690d726b74f4db37e0644f96d751a61",
"md5": "e6c126bfdc33a8859fefbe74325077ee",
"sha256": "c57d3ad9f786426cc0e16001c09de66c092916feeaa994c4576645a9beadf6e9"
},
"downloads": -1,
"filename": "codaio-0.6.12.tar.gz",
"has_sig": false,
"md5_digest": "e6c126bfdc33a8859fefbe74325077ee",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 19894,
"upload_time": "2024-05-08T08:57:43",
"upload_time_iso_8601": "2024-05-08T08:57:43.070934Z",
"url": "https://files.pythonhosted.org/packages/f4/d3/36f172b0f89aaf35bd51ab7f8ce48690d726b74f4db37e0644f96d751a61/codaio-0.6.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-08 08:57:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Blasterai",
"github_project": "codaio",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "codaio"
}