Skip to main content

Python wrapper for Coda.io API

CodaAPI PyPI - Python Version Code style: black Documentation Status PyPI PyPI - Downloads

codaio is in active development stage. Issues and PRs very welcome!

Installation

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/v1beta1)
  • CODA_API_KEY - your API key to use when initializing document 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.

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/v1beta1/docs/LINK', 'browserLink': 'https://coda.io/d/LINK', 'name': 'My Document', 'owner': 'your@email', 'createdAt': '2019-08-29T11:36:45.120Z', 'updatedAt': '2019-08-29T11:36:45.272Z'}

For full API reference for Coda class see documentation

Quickstart using codaio objects

codaio implements convenient classes to work with Coda documents: Document, Table, Row, Column and Cell.

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

# 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:

import pandas as pd

df = pd.DataFrame(table.to_dict())

Fetching a Cell

# 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

row['COLUMN_ID'] = 'foo'
# or
row['Column Name'] = 'foo'

Iterating over rows

# 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()

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)

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)

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

Testing

All tests are in the /tests folder. It's a little bit problematic to test against the live API since some responses may take a bit longer, so test results are not reliable enough to use a CI system.

Check out the fixtures if you want to improve the testing process.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codaio-0.4.11.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codaio-0.4.11-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file codaio-0.4.11.tar.gz.

File metadata

  • Download URL: codaio-0.4.11.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Windows/10

File hashes

Hashes for codaio-0.4.11.tar.gz
Algorithm Hash digest
SHA256 3331f318badc78a9dcccdd3aaa8fae8da3c8df8689f14561796c4dc5449b8888
MD5 7c984c14bf4ebac79317d8ba7db25cde
BLAKE2b-256 683fe284fd31e279fd3edde7012b02d3e905549e52ce1e5adef9b85ccd93d285

See more details on using hashes here.

File details

Details for the file codaio-0.4.11-py3-none-any.whl.

File metadata

  • Download URL: codaio-0.4.11-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Windows/10

File hashes

Hashes for codaio-0.4.11-py3-none-any.whl
Algorithm Hash digest
SHA256 2035803779904799ac78aa449a7951b9923fd3295d7bcd09c25a2a7f0f90bea8
MD5 9d6d6c1f033d070c95ae3c0abfe2c495
BLAKE2b-256 1eab7b0baf5442a9631a11f498fd6ce631edd090f49a6fdc467c640e0e4bad10

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.12

2 files

0.6.11

2 files

0.6.10

2 files

0.6.9

2 files

0.6.8

2 files

0.6.7

2 files

0.6.6

2 files

0.6.5

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.12

2 files

This release

0.4.11 This release

2 files

0.4.10

2 files

0.4.9

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.0

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page