Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lloydzhou/pybitable
将多维表格当数据库使用
https://github.com/lloydzhou/pybitable
Last synced: 27 days ago
JSON representation
将多维表格当数据库使用
- Host: GitHub
- URL: https://github.com/lloydzhou/pybitable
- Owner: lloydzhou
- Created: 2024-01-29T02:40:16.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-03-04T09:00:31.000Z (10 months ago)
- Last Synced: 2024-11-25T01:11:08.427Z (about 1 month ago)
- Language: Python
- Size: 45.9 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pybitable
```
from pybitable import Connection, ConnectionPooldb_url = 'bitable+pybitable://:@open.feishu.cn/'
# 支持使用personal_base_token访问多维表格,这里建议使用后面一种写法,sqlalchemy打印日志的时候,会将personal_base_token当成密码显示星号
db_url = 'bitable+pybitable://@open.feishu.cn/'
db_url = 'bitable+pybitable://:@open.feishu.cn/'conn_pool = ConnectionPool(
maxsize=10,
connection_factory=lambda: Connection(db_url),
)with conn_pool.connect() as connection:
print('connect', connection)
cursor = connection.cursor()
result = cursor.execute('select * from tbl2w2QJgo6YCthm')
cursor.close()
```## cli
```
pip install pybitable[cli]pybitable -h base-api.feishu.cn -p
pybitable -h open.feishu.cn -u -p
pybitable bitable+pybitable://:@open.feishu.cn/
pybitable bitable+pybitable://:@base-api.feishu.cn/
```
![image](https://github.com/lloydzhou/pybitable/assets/1826685/06a2aa06-6e9f-4ba8-9c9c-c738e7d891e5)## using sqlalchemy
```
pip install pybitable[sqlalchemy]from sqlalchemy import create_engine, Column, String, Text, text
from sqlalchemy.orm import sessionmaker, declarative_baseengine = create_engine(db_url, echo=False)
Session = sessionmaker(engine)with engine.connect() as conn:
result = conn.execute(
text("select `文本` as a from tblID0QbOnjktwdC")
)
for row in result:
print(f"{row}")Base = declarative_base()
class BITable1(Base):
__tablename__ = 'tblID0QbOnjktwdC'
record_id = Column(String(32), primary_key=True)
文本 = Column(Text, nullable=True, server_default=text("''"), comment="文本")
单选 = Column(String(32), nullable=True, server_default=text("''"), comment="单选")
多选 = Column(Text, nullable=True, server_default=text("''"), comment="多选")with Session.begin() as session:
for item in session.query(BITable1).all():
print('record_id: ', item.record_id, '文本: ', item.文本, '单选', item.单选, '多选', item.多选)print('engine', engine, BITable1)
```![image](https://github.com/lloydzhou/pybitable/assets/1826685/c12009c4-0ea0-4a30-babb-97a6604142e7)
![image](https://github.com/lloydzhou/pybitable/assets/1826685/fa85ed0b-2474-4caf-a4ef-5185afceebce)