Skip to main content

Client for the baserow.io API.

Project description

baserow-client

A Python client for Baserow.io with simple ORM capabilities.

Note: This package is currently under development. Some APIs may break without prior notice.

Installation

$ pip install baserow-client

Getting started

BaserowClient

The Baserow client provides direct access to many of the Baserow API endpoints. It must be initialized with the URL to your Baserow instance as well as a JWT or Token. Without authentication, the client may still be used to generate a JWT from user credentials.

from baserow.client import BaserowClient

client = BaserowClient('https://baserow.io', jwt='...')
client = BaserowClient('https://baserow.io', token='...')

client = BaserowClient('https://baserow.io')
user, jwt = client.token_auth('username', 'password')

If you use the login() method instead of token_auth(), the JWT will be installed into the same client right away.

Operations that require a JWT

Meta operations such as listing available applications, tables, fields or creating/updating/deleting databases, etc. require a JWT.

Examples

for db in client.list_all_applications():
  print(db, [t.name for t in db.tables])

for table in client.list_database_tables(13):
  print(table)

for field in client.list_database_table_fields(45):
  print(field)

Create/Read/Update/Delete rows

These operations do not require a JWT and can be performed with a long-lived token instead, which can be created from the Baserow UI. The Baserow Python client currently supports reading data only.

Example

is_john_smith = Column('field_281').equal('John Smith')
page = client.list_database_table_rows(45, filter=[is_john_smith])
print(page.results)

You can use the paginate_database_table_rows() convenience method to receive an iterator for all pages.

Object-relational mapper

The Baserow Python client comes with basic ORM capabilities.

Note: The ORM API is not Mypy compatible. Support could be added by implementing a Mypy plugin.

Define models

# myapp/models.py

from baserow.orm import Column, ForeignKey, Model

class Product(Model):
  name = Column('Name')
  price = Column('Price')

class Customer(Model):
  name = Column('Name')
  favorite_products = ForeignKey('Favorite Products', Product)

Generate a database mapping

Because the database schema cannot be introspected using a normal token, it is necessary to generate a mapping for the ORM using a JWT. The easiest way to do this is to use the Baserow ORM command-line interface.

$ python -m baserow.orm \
    'My web shop' myapp.models.Product:Produces myapp.models.Customer:Customers \
    --url https://baserow.io --user my-email@example.org --write-to var/conf/mapping.json

You can specify --password '...' to avoid the password prompt, or directly pass a JWT with --jwt '...'.

Database connection

# myapp/__main__.py

from baserow.client import BaserowClient
from baserow.orm import Database, DatabaseMapping
from .models import Product, Customer

client = BaserowClient('https://baserow.io', token='...')
db = Database(client, DatabaseMapping.load('var/data/mapping.json'))

alice = list(db.select(Customer).filter(Customer.name.contains('Alice')))[0]
print('Alice likes:')
for product in alice.favorite_products:
  print(f'- {product.name}')

Copyright © 2021 Niklas Rosenstein

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

baserow-client-0.2.1.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

baserow_client-0.2.1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file baserow-client-0.2.1.tar.gz.

File metadata

  • Download URL: baserow-client-0.2.1.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

File hashes

Hashes for baserow-client-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6bb260c34bfd2325866bea2cd7bc5dd746ce9a95fb819a5cbe64f8ce5ab1d4fd
MD5 0565f45f9fb42044e8da31d81cb62622
BLAKE2b-256 281700fa70a2de47b2655288152b24162f30063580b05b3529cfd193749bf24b

See more details on using hashes here.

File details

Details for the file baserow_client-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: baserow_client-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10

File hashes

Hashes for baserow_client-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d0a77f72d5dc7f2390e3f535167fefe1dc58dc61e4cb2a201de6b0495d751869
MD5 c793cb44aeaa83c1a2e3aedfc1141011
BLAKE2b-256 d6ed27428dc0e77ead89f137783b84e8a892d2ef6dad7b8b96143ec700e5ed1d

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