|
| 1 | +# NocoDB Python Client |
| 2 | + |
| 3 | +NocoDB is a great Airtable alternative. This client allows python developers |
| 4 | +to use NocoDB API in a simple way. |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +### Client configuration |
| 9 | +```python |
| 10 | +from nocodb.nocodb import NocoDBProject, APIToken, JWTAuthToken |
| 11 | +from nocodb.filters import InFilter, EqFilter |
| 12 | +from nocodb.infra.requests_client import NocoDBRequestsClient |
| 13 | + |
| 14 | + |
| 15 | +# Usage with API Token |
| 16 | +client = NocoDBRequestsClient( |
| 17 | + # Your API Token retrieved from NocoDB conf |
| 18 | + APIToken("YOUR-API-TOKEN"), |
| 19 | + # Your nocodb root path |
| 20 | + "http://localhost:8080" |
| 21 | +) |
| 22 | + |
| 23 | +# Usage with JWT Token |
| 24 | +client = NocoDBRequestsClient( |
| 25 | + # Your API Token retrieved from NocoDB conf |
| 26 | + JWTAuthToken("your.jwt.token"), |
| 27 | + # Your nocodb root path |
| 28 | + "http://localhost:8080" |
| 29 | +) |
| 30 | +``` |
| 31 | + |
| 32 | +### Project selection |
| 33 | +```python |
| 34 | +# Be very carefull with org, project_name and table names |
| 35 | +# weird errors from nocodb can arrive if they are wrong |
| 36 | +# example: id is not defined... |
| 37 | +# probably they will fix that in a future release. |
| 38 | +project = NocoDBProject( |
| 39 | + "noco", # org name. noco by default |
| 40 | + "myproject" # project name. Case sensitive!! |
| 41 | +) |
| 42 | + |
| 43 | +``` |
| 44 | + |
| 45 | +### Table rows operations |
| 46 | +```python |
| 47 | +table_name = "tablename" |
| 48 | + |
| 49 | +# Retrieve a page of rows from a table |
| 50 | +table_rows = client.table_row_list(project, table_name) |
| 51 | + |
| 52 | +# Retrieve the first 10000 rows |
| 53 | +table_rows = client.table_row_list(project, table_name, params={'limit': 10000}) |
| 54 | + |
| 55 | +# Skip 100 rows |
| 56 | +table_rows = client.table_row_list(project, table_name, params={'offset': 100}) |
| 57 | + |
| 58 | +# Filter the query |
| 59 | +# Currently only one filter at a time is allowed. I don't know how to join |
| 60 | +# multiple conditions in nocodb dsl. If you know how please let me know :). |
| 61 | +table_rows = client.table_row_list(project, table_name, InFilter("name", "sam")) |
| 62 | +table_rows = client.table_row_list(project, table_name, filter_obj=EqFilter("Id", 100)) |
| 63 | + |
| 64 | +# Retrieve a single row |
| 65 | +row_id = 10 |
| 66 | +row = client.table_row_detail(project, table_name, row_id) |
| 67 | + |
| 68 | +# Create a new row |
| 69 | +row_info = { |
| 70 | + "name": "my thoughts", |
| 71 | + "content": "i'm going to buy samuel a beer because i love this module", |
| 72 | + "mood": ":)" |
| 73 | +} |
| 74 | +client.table_row_create(project, table_name, row_info) |
| 75 | + |
| 76 | +# Update a row |
| 77 | +row_id = 2 |
| 78 | +row_info = { |
| 79 | + "content": "i'm going to buy samuel a new car because i love this module", |
| 80 | +} |
| 81 | +client.table_row_update(project, table_name, row_id, row_info) |
| 82 | + |
| 83 | +# Delete a row (only if you've already bought me a beer) |
| 84 | +client.table_row_delete(project, table_name, row_id) |
| 85 | +``` |
| 86 | + |
| 87 | +## Author notes |
| 88 | + |
| 89 | +I created this package to bootstrap some personal projects and I hope it |
| 90 | +will help other developers from the python community. It's not completed but |
| 91 | +it has what I needed: A full CRUD with some filters. |
| 92 | + |
| 93 | +Feel free to add new capabilities by creating a new MR. |
| 94 | + |
| 95 | +## Contributors |
| 96 | + |
| 97 | +- Samuel López Saura |
0 commit comments