Python client for NocoDB API v2
Project description
nocodb-api
Python client for NocoDB API v2
Install
Install from pypi:
pip install nocodb-client
Install from Github:
pip install "nocodb-api@git+https://github.com/liuli01/nocodb-api"
Quickstart
#%%
import json
import os
from nocodb import NocoDB
from nocodb.Column import Column
import logging
logging.basicConfig()
logging.getLogger('nocodb').setLevel(level=logging.DEBUG)
CONFIG = {
"NOCO_URL": "https://app.nocodb.com",
"NOCO_API_KEY": "",
"NOCO_BASE_ID": "",
"TIMEOUT": "30"
}
try:
with open("test_config.json") as config_file:
CONFIG.update(json.load(config_file))
except FileNotFoundError:
for s in CONFIG:
if s in os.environ:
CONFIG[s] = os.environ[s]
noco = NocoDB(url=CONFIG["NOCO_URL"],
api_key=CONFIG["NOCO_API_KEY"])
base = noco.get_base(base_id=CONFIG["NOCO_BASE_ID"])
[t.delete() for t in base.get_tables()]
#%%
"""
数据新增操作
"""
#%% 创建表
base.create_table("test_01")
#%% 获取表对象
table=base.get_table_by_title("test_01")
#%% 增加一条记录
table.create_record(Title="First Record")
# %% 创建多条记录
table.create_records([{"Title": "Second Record"}, {"Title": "Third Record"}])
#%% 新增列
table.create_column("Update", "Update", Column.DataType.SingleLineText)
"""
数据修改操作
"""
# %% 更新1条记录
table.update_record(Id="1",Update="First Record Updated")
# %% 更新多条记录
table.update_records([{"Id":"2","Update": "Second Record Updated"},{"Id":"3","Update": "Third Record Updated"}])
"""
数据查询操作
"""
# 数据查询操作
#%% 根据id查看一条记录
record_1=table.get_record(1).metadata
#%% 根据Id查看记录的某个字段
value_1=table.get_record(1).get_value("Title")
#%% 根据字段值筛选获取记录
field_records=table.get_records_by_field_value("Title","First Record")
[print(r.metadata) for r in field_records]
# %% 根据自定义条件获取记录
condition_records=table.get_records(params={"where": f"(Title,eq,First Record)"})
[print(r.metadata) for r in condition_records]
# %% 获取所有记录元数据
records=table.get_records()
[print(r.metadata) for r in table.get_records()]
# %% 获取所有记录数量
print(table.get_number_of_records())
"""
数据删除操作
"""
# %% 删除一条记录
table.delete_record(1)
#%%
table.delete_records([2,3])
# %%
Get debug log:
import logging
from nocodb import NocoDB
logging.basicConfig()
logging.getLogger('nocodb').setLevel(logging.DEBUG)
# Now every log is visible.
# Limit to submodules:
logging.getLogger('nocodb.Base').setLevel(logging.DEBUG)
Development
python -m venv .venv
. ./.venv/bin/activate
Tests in Docker
Create a file test_config.json with the parameters, or change the Environment Variables in tests/Dockerfile, than run:
docker run --rm -it $(docker build -q -f tests/Dockerfile .)
Official docs
Documentation with pdoc
TODO
pip install -e ".[doc]"
pdoc -d google nocodb
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nocodb_client-0.0.1.tar.gz
(46.5 kB
view details)
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 nocodb_client-0.0.1.tar.gz.
File metadata
- Download URL: nocodb_client-0.0.1.tar.gz
- Upload date:
- Size: 46.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91aa513d7922f53b4319f74002350a224f00db04fe34113158d060922091a824
|
|
| MD5 |
478bf8800a6715955e13cce0f49d0ece
|
|
| BLAKE2b-256 |
20a82a6ace6c9417035f08803e6c1705195b004cd86f59dcbb0d41ff0f851217
|
File details
Details for the file nocodb_client-0.0.1-py3-none-any.whl.
File metadata
- Download URL: nocodb_client-0.0.1-py3-none-any.whl
- Upload date:
- Size: 33.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc239f9cfdec8a7dc33f7b298e8af667ac977bc914652dff98e20d2f76b8cade
|
|
| MD5 |
30ceab99c1eb50b9d3d82fb13455aaec
|
|
| BLAKE2b-256 |
bc1857dbbca4ed4be1cb40e1df3cfb0ee5c628d457d816d416d2e351cb0d62f4
|