Skip to main content

PycoDB

Python client for NocoDB with a Django ORM–style layer.

Quick start

from pycodb import DataBase, BaseTable, RepositoryManager

DataBase.DOMAIN = 'your-host:8080'
DataBase.NOCODB_API_KEY = 'your-token'

class AppData(DataBase):
    class Users(BaseTable):
        view_id = '...'
        table_id = '...'

class Users(RepositoryManager):
    data_source = AppData

repo = Users()
for row in repo.objects.filter(status='active').order_by('-CreatedAt')[:50]:
    print(row.name)

Layers

Layer Classes Role
HTTP NocoClient Transport, errors (NocoAPIError)
Table API api/, BaseTable NocoDB v2/v3 records CRUD, links, upload
Query query/ Lookups, Q, build_where, nested params
Gateway DataBase Per-table access, DataProxy compatibility
ORM-like Manager, QuerySet, Model Lazy queries, Django-style API
Meta MetaClient Bases, tables, columns, link fields

Package layout (query/)

pycodb/query/
  operators/lookups.py   # __gt, __in, escape_value, build_where
  expressions.py       # Q (& | ~)
  nested.py            # prefetch_related params

Legacy imports from pycodb.where import Q still work.

QuerySet (0.2+)

objects.filter() returns a lazy QuerySet (not DataProxy). Evaluate with list(), for, or get():

qs = repo.objects.filter(campaign='x').order_by('-Id')
qs.count()
qs.first()
qs.get(Id=1)  # raises DoesNotExist / MultipleObjectsReturned

Model (0.3+)

from pycodb import Model, RepositoryManager

class Banner(Model):
    class Meta:
        pk = 'Id'

class Banners(RepositoryManager):
    model = Banner
    data_source = AppData

banner = Banners.objects.create(title='Hello')
banner.title = 'Updated'
banner.save(update_fields=['title'])
banner.refresh_from_db()
banner.delete()

obj, created = Banners.objects.get_or_create(slug='x', defaults={'title': 'Hi'})
Banners.objects.filter(status='live').values_list('title', flat=True)
mapping = Banners.objects.in_bulk([1, 2, 3])

QuerySet extras

Method Description
get_or_create / update_or_create Django-style upsert
bulk_create Insert many rows
values_list Tuples or flat=True
only Limit returned columns (+ pk)
in_bulk Dict keyed by pk
earliest / latest First row by sort
Q Q(a=1) | Q(b=2) composable filters

API v3 (0.4+)

DataBase.API_VERSION = 'v3'
DataBase.BASE_ID = 'p_your_base_id'

class AppData(DataBase):
    class Tasks(BaseTable):
        base_id = 'p_your_base_id'  # optional per-table override
        view_id = '...'
        table_id = 'm...'

v3 responses are normalized to the same {Id, ...} shape as v2.

Meta API

meta = DataBase.meta()
bases = meta.list_bases()
tables = meta.list_tables('p_base_id')
columns = meta.get_table_columns('m_table_id')
links = meta.find_link_fields('m_table_id')  # linkFieldId for link APIs
# Expand linked data in list (v2 nested[] / v3 nestedPage)
qs = repo.objects.filter(status='open').prefetch_related({
    'cl_link_field_id': ['Title', 'Status'],
})

# Per-record linked rows
banner.get_linked('cl_link_field_id', fields=['Title'])
banner.link('cl_link_field_id', 10, 11)
banner.unlink('cl_link_field_id', 10)

Configuration

Attribute Default Description
DataBase.DOMAIN — Host or full URL
DataBase.NOCODB_API_KEY — API token (xc-token)
DataBase.SCHEME http http or https
DataBase.TIMEOUT 30 Request timeout (seconds)
DataBase.API_VERSION v2 v2 or v3
DataBase.BASE_ID — Required for v3 data API

Tests

python3 -m unittest discover -s tests -v

Metadata

Release files for pycodb 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycodb 0.2.0
File Size Uploaded Provenance Actions
pycodb-0.2.0.tar.gz 17.0 kB Without provenance Details for pycodb-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pycodb 0.2.0
File Interpreter ABI Platform Actions
pycodb-0.2.0-py3-none-any.whl Python 3 none any Details for pycodb-0.2.0-py3-none-any.whl

Total release size: 42.0 kB

Release files / pycodb-0.2.0.tar.gz

Download URL pycodb-0.2.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7f473ff9fc7fd47080f9b3adb9483262c8658fd5eac3664ca4a4129fc5e4cfa4
BLAKE2b-256 checksum
How to use checksums
5be9a120150330d43e137e9656bb93d46cfa9fe1eb832357ecdf0a4e5d79dd55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.11.2 Darwin/23.5.0

Release files / pycodb-0.2.0-py3-none-any.whl

Download URL pycodb-0.2.0-py3-none-any.whl
Size 25.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2448d607a34d54c7827156388685a1548ceb438b2b7b1cf79672bd154fdf3619
BLAKE2b-256 checksum
How to use checksums
0f5f4eee605e6f349ec21d9796662b6b86051355b04a9822941c46b2b1381514
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.11.2 Darwin/23.5.0

Security for pycodb 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page