用于AirTable的Python客户端库
项目描述
Python接口,用于访问Airtable的REST API - https://airtable.com -
对于JavaScript爱好者:https://github.com/Airtable/airtable.js
安装
Airtable Python使用Requests.py:请确保您已安装,通过运行
$ pip install requests
入门
一旦您通过Web界面创建了一个新的基础和新的表,您就可以开始使用Airtable Python了。
from airtable import airtable
at = airtable.Airtable('BASE_ID', 'API_KEY')
at.get('TABLE_NAME')
以下是从餐厅示例基础返回的示例响应
{u'records': [
{u'fields': {u'Diet': u'Kosher or Halal',
u'Friendly Restaurants': [u'recr0ITqq9C1I92FL', u'recGeAJLw0ZkbwdXZ'],
u'Icon': [{u'filename': u'no-pig.jpg',
u'id': u'attzKGOBbjndOx0FU',
u'size': 34006,
u'thumbnails': {u'large': {u'height': 202,
u'url': u'https://dl.airtable.com/trmtq3BaRoa0sWnyffWZ_large_no-pig.jpg',
u'width': 256},
u'small': {u'height': 36,
u'url': u'https://dl.airtable.com/yzuRv5CyRs2PVH4fDvCe_small_no-pig.jpg',
u'width': 46}},
u'type': u'image/jpeg',
u'url': u'https://dl.airtable.com/DyGOjAASze6AIkQxFpDv_no-pig.jpg'}],
u'People': [u'Annie', u'Maryam']},
u'id': u'rec5sD6mBBd0SaXof'},
...
API参考
可用方法与REST API非常相似
获取
给定一个表名,检索一个或多个记录。
at.get(table_name, table_name, record_id=None, limit=0, offset=None,
filter_by_formula=None, view=None, max_records=0, fields=[])
其中
table_name (required) is a string representing the table name record_id (optional) is a string, which fetches a specific item by id. If not specified, all items are fetched limit (optional) is an integer, and it can only be specified if record_id is not present, and limits the number of items fetched (see pageSize in the AirTable documentation) offset is a string representing the record id from which we start the offset filter_by_formula (optional) is a string to filter the retrieving records (see filterByFormula in the AirTable documentation) max_records (optional) is the total number of records that will be returned (see maxRecords in the AirTable documentation) fields (optional) is a list of strings with the field names to be returned
迭代
给定一个表名,检索所有记录。
at.iterate(table_name, table_name, limit=0, offset=None,
filter_by_formula=None, view=None, max_records=0, fields=[])
其中
table_name (required) is a string representing the table name limit (optional) is an integer, and it can only be specified if record_id is not present, and limits the number of items fetched (see pageSize in the AirTable documentation) offset is a string representing the record id from which we start the offset filter_by_formula (optional) is a string to filter the retrieving records (see filterByFormula in the AirTable documentation) max_records (optional) is the total number of records that will be returned (see maxRecords in the AirTable documentation) fields (optional) is a list of strings with the field names to be returned
注意:这返回一个生成器,您可以使用它来遍历每条记录
# example with similar results of at.get
result = { "records": [] }
for r in self.at.iterate(self.table, fields=fields):
result["records"].append(r)
创建
在表中创建一个新条目,并返回新创建的条目及其新ID。
at.create(table_name, data)
其中
table_name (required) is a string representing the table name data (required) is a dictionary containing the fields and the resepective values
更新
更新表中特定条目的一些字段。未明确包含的字段将不会更新
at.update(table_name, record_id, data)
其中
table_name (required) is a string representing the table name record_id (required) is a string representing the item to update data (required) is a dictionary containing the fields (and the resepective values) to be updated
更新全部
类似于前面的方法,但更新所有字段,清除请求中未包含的字段。
at.update_all(table_name, record_id, data)
删除
从表中删除特定记录
at.delete(table_name, record_id)
其中
table_name (required) is a string representing the table name record_id (required) is a string representing the item to update
发布
要发布,给Git仓库添加一个新版本号,然后将该标签推送到GitHub,然后Travis CI将完成剩余工作。
项目详情
下载文件
下载您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
airtable-0.4.8.tar.gz (13.0 kB 查看哈希值)
构建分布
airtable-0.4.8-py2.py3-none-any.whl (8.1 kB 查看哈希值)