firetable package

Submodules

firetable.commands module

Airtable API command classes.

Copied fairly faithfully from the Airtable API documentation. I wouldn’t have known where to begin if it weren’t for nicocanali/airtable-python.

Why am I using the command design pattern? I don’t know. I don’t even know if I’m using it correctly. It seemed like a good idea. I was thinking something about validation methods, eventually, I think.

Some day.

The text width is set to 54, so I can see it comfortably in Pythonista for iOS.

class firetable.commands.Command(endpoint, **kwargs)[source]

Bases: object

execute()[source]
class firetable.commands.Delete(endpoint, **kwargs)[source]

Bases: firetable.commands.Command

Delete command class for Airtable API.

Parameters:endpoint (Endpoint) – An Endpoint object pointing to a record.
class firetable.commands.Get(endpoint, **kwargs)[source]

Bases: firetable.commands.Command

Get command class for Airtable API.

Parameters:
  • endpoint (Endpoint) – An Endpoint object pointing to a record or a table.
  • note (.) – record and table endpoints. However, per the Airtable API, the following parameters only apply to table endpoints. However again, issuing a command to a record endpoint is essentially the same as issuing a get command to the table endpoint with offset=<recordID> and maxRecords=1. So, I think I will implement it like that. The upshot, therefore, is that you can restrict the data using the fields parameter. You can still send the filterByFormula, pageSize, and sort parameters and they will (I think) have no effect. I’m not sure what will happen if you send a view parameter. Probably nothing if the record is included in the view and an error if it is not. We’ll see.
  • fields (Optional[List[str]]) – List of fields to be returned.
  • filterByFormula (Optional[str]) – A formula for filtering records.
  • maxRecords (Optional[int]) – Max number of records to return.
  • pageSize (Optional[int]) –

    Max number of records to return.

    Airtable restricts this to a maximum of 100, which is also the default.

  • sort (Optional[List[Sort]]) –

    List of sort objects specifying how the records should be sorted.

    Since we’re using Python here, there’s not much reason you can’t do this after the fact.

  • view (Optional[str]) –

    Name or ID of a view in the table.

    This is a useful shortcut for downloading records based on preset filters and sorts.

  • offset (Optional[str]) –

    The record ID to start with when downloading.

    This is necessary because of the 100-record page size limit. I can’t think of any other use for it. This package should be able to take care of this automatically soon.

Examples

>>> from endpoints import TableEndpoint
>>> e = TableEndpoint(
...     default_base,
...     'Restaurants',
...     )
>>> g = Get(e)
>>> g
... 
Get(TableEndpoint(base='app...', table='Restaurants'))
>>> print g
... 
Method: GET
URL: https://api.airtable.com/v0/app.../Restaurants
Headers: {'Authorization': 'Bearer key...'}
Params: {}
>>> g()
... 
[{u'records': [{u'createdTime': ...}]}]
class firetable.commands.Patch(endpoint, **kwargs)[source]

Bases: firetable.commands.Command

Patch command class for Airtable API.

Must be sent to a record endpoint. Updates selected fields on a record. Any field you don’t include will be left alone. To update a field that links to other records, get the original list of recordIDs, add/remove as needed, and send the new list.

Parameters:
  • endpoint (Endpoint) – An Endpoint object pointing to a record.
  • fields ([Dict]) – The updated values for the new record.
class firetable.commands.Post(endpoint, **kwargs)[source]

Bases: firetable.commands.Command

POST Command for the Airtable API.

Parameters:
  • endpoint (Endpoint) – An Endpoint object pointing to a table.
  • note (.) – table endpoint. They create a new record in that table.
  • fields (Optional[Dict]) – The initial values for the new record. You can include all, some or none of the fields.
  • typecast (Optional[bool]) – Tell Airtable to do some automatic data conversion. I don’t understand the implications yet, but pass it if you wish. Disabled by default.

Examples

>>> from endpoints import TableEndpoint
>>> e = TableEndpoint(
...     default_base,
...     'Restaurants',
...     )
>>> post = Post(e, fields={
...     'Name': 'Five Guys',
...     'Cost': '$',
...     'Notes': 'The small fry is more than plenty.'
...             })
>>> post
... 
Post(TableEndpoint(base='app...', table='Restaurants'))
>>> print post.request.url
... 
Method: POST
URL: https://api.airtable.com/v0/app.../Restaurants
Headers: {'Content-Length': '0', 'Authorization': 'Bearer key...'}
Params: {'fields': {'Notes': ..., 'Cost': ..., 'Name': ...}}
>>> try:
...     post()
... except Exception as e:
...     print "Is the internet down?"
... 
class firetable.commands.Put(endpoint, **kwargs)[source]

Bases: firetable.commands.Command

Put command class for Airtable API.

Parameters:
  • endpoint (Endpoint) – An Endpoint object pointing to a record.
  • fields ([Dict]) – The updated values for the record. (All other fields will be obliterated!)
  • typecast (Optional[bool]) – Tell Airtable to do some automatic data conversion. I don’t understand the implications yet, but pass it if you wish. Disabled by default.
firetable.commands.main()[source]

firetable.endpoints module

Endpoints classes for Airtable API.

An endpoint is reference to a table or a record.

Creating a Table Endpoint

>>> BASE = 'app0123456789abcd'
>>> contacts = TableEndpoint(
...     base=BASE,
...     table='Contacts'
...     )
>>> contacts
... 
TableEndpoint(base='app0123456789abcd',
    table='Contacts')
>>> contacts.url
'https://api.airtable.com/v0/app0123456789abcd/Contacts'

Creating a Record Endpoint

>>> john = RecordEndpoint(
...     base=BASE,
...     table='Contacts',
...     record='rec0123456789abcd'
...     )
>>> john
... 
RecordEndpoint(base='app0123456789abcd',
    table='Contacts',
    record='rec0123456789abcd')
>>> john.url
'https://api.airtable.com/v0/app0123456789abcd/Contacts/rec0123456789abcd'

Sugar

Getting URLs through Endpoint.__str__()

You can also get an endpoint’s URL by getting its str representation:

>>> print john
https://api.airtable.com/v0/app0123456789abcd/Contacts/rec0123456789abcd

Dynamic Endpoint Creation

Instead of instantiating endpoints directly, you can use make_endpoint to get an endpoint whose type is based on the arguments you provide. Combine it with the star notation and endpoint creation becomes very dynamic:

>>> a = (BASE, 'Cakes')
>>> b = (BASE, 'Cakes', 'rec0123456789abcd')
>>> make_endpoint(*a)
TableEndpoint(base='app0123456789abcd', table='Cakes')
>>> make_endpoint(*b)
RecordEndpoint(base='app0123456789abcd', table='Cakes', record='rec0123456789abcd')
class firetable.endpoints.Endpoint[source]

Bases: object

get()[source]
url
class firetable.endpoints.RecordEndpoint[source]

Bases: firetable.endpoints.Endpoint, firetable.endpoints.RecordEndpoint

get()[source]
class firetable.endpoints.TableEndpoint[source]

Bases: firetable.endpoints.Endpoint, firetable.endpoints.TableEndpoint

get(**kwargs)[source]
firetable.endpoints.make_endpoint(base, table, record=None)[source]
firetable.endpoints.testmod()[source]

firetable.cli module

CLI

Command Line Interface based on click.

Copied from http://chase-seibert.github.io/blog /2014/03/21/python-multilevel-argparse.html. No relation, I don’t think. ;)

class firetable.cli.CLI(raw_args)[source]

Bases: object

delete()[source]
get(raw_args)[source]
patch()[source]
post()[source]
put()[source]
firetable.cli.fire()[source]

Module contents