A Python package to operate with Feishu/Lark bitable
Project description
python-bitable
A Python package to operate with Feishu/Lark bitable
Install
pip install bitable
Usage
Quick Start
from bitable import Table
table = Table(BASE_ID, AUTH_TOKEN, 'TABLE_NAME')
# you may also use table_id: Table(BASE_ID, AUTH_TOKEN, table_id=TABLE_ID)
# select records
records = table.select() # select all records
records = table.select({'field_name1': 'value1', 'field_name2': 'value2'}) # select with conditions
records = table.select(Greater('FieldValue', 90))
records = table.select(Or(Greater('FieldValue', 90), And({'FieldSingle': 'A'}, Contain('FieldText', 'text_value')))) # select with complex conditions
# insert records
table.insert({'field_name1': 'value1', 'field_name2': 'value2'}) # insert a record
table.insert([{'field_name1': 'value1', 'field_name2': 'value2'}, {'field_name1': 'value3', 'field_name2': 'value4'}]) # insert multiple records
# update records
table.update({'FieldMultiple': ['B', 'A'], 'FieldDate':'2024-12-21'}, where={'FieldText': 'text_value'}) # update records with where conditions
result = table.select({'FieldText': 'HelloTestUpdate'})[0]
result['FieldText'] = 'new_value'
table.update(result) # update records with record object
# delete records
self.table.delete(where={'FieldText': 'HelloDelete'}) # with where condition
result = table.select({'FieldText': 'HelloTestUpdate'})[0]
self.table.delete(results) # with selected object
Load a table
from bitable import Table
table = Table(BASE_ID, BASE_TOKEN, 'TABLE_NAME')
BASE_ID can be found at the bitable's URL after 'base/'
AUTH_TOKEN can be found following these steps:
-
click the "Base extensions" icon on the top right:
-
click "Customize" on the bottom right
-
click "Get Authorization Code"
Select Records
select all records with just select():
records = table.select()
every record is a dict of field name => value. With '_id' key for the record id additionally.
simple conditions like x==y can be passed in as a dict:
records = table.select({'field_name1': 'value1', 'field_name2': 'value2'})
use operators to construct complex conditions:
records = table.select(Greater('FieldValue', 90))
records = table.select(Or(Greater('FieldValue', 90), And({'FieldSingle': 'A'}, Contain('FieldText', 'text_value'))))
list of operators:
- Equal: "==" operator
- Not: "!=" operator
- Contain: if a string field contains a substring, or a multiple-select field contains an element
- NotContain
- Empty
- NotEmpty
- Greater: ">" operator
- GreaterEqual ">=" operator
- Less
- LessEqual
for date fields, use 'YYYY-mm-dd' format, or one of the following:
Today(), Yesterday(), Tomorrow(), CurrentWeek(), LastWeek(), CurrentMonth(), LastMonth(), Past7Days(), Next7Days(), Past30Days(), Next30Days()
Insert Records
insert a record with insert():
table.insert({'field_name1': 'value1', 'field_name2': 'value2'})
insert multiple records with a list:
table.insert([{'field_name1': 'value1', 'field_name2': 'value2'}, {'field_name1': 'value3', 'field_name2': 'value4'}])
Update Records
if record is a record dict selected from the table, you can change its content, and update it with update():
(in fact, it uses '_id' key to locate the record)
table.update(record)
you can also update records with where conditions:
table.update({'field_name1': 'new_value1', 'field_name2':'new_value2'}, where={'condition_field_name': 'text_value'})
Delete Records
delete a record selected from the table with delete():
(similar to update(), it uses '_id' key to locate which record to delete)
table.delete(record)
batch delete records with where conditions:
table.delete(where={'field_name': 'field_value'})
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bitable-1.0.2.tar.gz.
File metadata
- Download URL: bitable-1.0.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f43c2f0371963b525779faa98d1b8e70dafe06de990c79e299bf550003b06545
|
|
| MD5 |
e48e80ab7a366461b048af48a4b0101b
|
|
| BLAKE2b-256 |
6074498f6834ef020726dc63a27499dc4f56cbf723444658112f22691e6b2ade
|
File details
Details for the file bitable-1.0.2-py3-none-any.whl.
File metadata
- Download URL: bitable-1.0.2-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16ba9a697571e2a36826e25336a3445367d4aef731e9a2854d8eda0a79bc4ecc
|
|
| MD5 |
d9a9dc1dd1a092e2ce3cb175239f1057
|
|
| BLAKE2b-256 |
9cb43ccb73622517262718e04077b42ba057dd811335e34b9db3c9001e7b991e
|