Skip to main content

A Python wrapper around Lark bitable to sql.

Project description

pybitable

from pybitable import Connection, ConnectionPool

db_url = 'bitable+pybitable://<app_id>:<app_secret>@open.feishu.cn/<app_token>'

# 支持使用personal_base_token访问多维表格,这里建议使用后面一种写法,sqlalchemy打印日志的时候,会将personal_base_token当成密码显示星号
db_url = 'bitable+pybitable://<personal_base_token>@open.feishu.cn/<app_token>'
db_url = 'bitable+pybitable://:<personal_base_token>@open.feishu.cn/<app_token>'

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

using sqlalchemy

from sqlalchemy import create_engine, Column, String, Text, text
from sqlalchemy.orm import sessionmaker, declarative_base

engine = 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

image

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

pybitable-0.0.9.tar.gz (9.4 kB view details)

Uploaded Source

File details

Details for the file pybitable-0.0.9.tar.gz.

File metadata

  • Download URL: pybitable-0.0.9.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for pybitable-0.0.9.tar.gz
Algorithm Hash digest
SHA256 4885138de25dc34a78ebf8864554c6deaa49425e2ea3ee7e162839205102ff19
MD5 8a38a97a12a74d9c75efa418cdf64763
BLAKE2b-256 7c822b6fa7c87704e829e63a9c2564be4c631a0e1f5faff4bda48ed51d9799c6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page