Schema Object
Classes:
|
Database Schema object for Notion API |
- class Schema(columns: Union[Dict[str, str], List[str]], types: Optional[List[str]] = None, id=False)[source]
Bases:
objectDatabase Schema object for Notion API
Properties:
labels (list): A list of column names types (list): A list of types
Creating a schema:
Can be created in a few different ways: 1. From a dictionary that maps column names to types: .. rubric:: Example
>>> schema = Schema({"Name": "title", "Age": "number"})
2. From a list of column names and a list of types: .. rubric:: Example
>>> schema = Schema( = ["Name", "Age"], types = ["title", "number"])
- param columns:
A dictionary that maps column names to types, or a list of column names.
- type columns:
dict|list
- param types:
Required if columns is a list. A list of types. Defaults to None.
- type types:
list, optional
- raises ValueError:
If columns is a list, then types must be a list of types.
- raises ValueError:
If list size of columns does not match the size of types.
- returns:
A schema object that can be used to update, create a new database, or create a new row
- rtype:
Schema
Modify or add to a schema:
To add a new column, simply set the value of a column to a new type. .. rubric:: Example
>>> schema = Schema({"Name": "title", "Age": "number"}) >>> schema["Is Student"] = "checkbox" >>> schema {'Name': 'title', 'Age': 'number', 'Is Student': 'checkbox'}
To update a property’s configuration, use get and access the property object directly. .. rubric:: Example
>>> schema = Schema({"Name": "title", "Salary": "number"}) >>> schema["Salary"]["format"] = "dollar"
To update a notion database
These are not yet implemented. This will allow you to update a database’s schema using id and names for notion columns:
>>> schema = Schema({"Name": "title", "Salary": "number"}) >>> schema.rename("Name", "Full Name")
Attributes:
Methods:
from_notion(data)alias for from_database
from_database(response)- property labels: List[str]
- property types: List[str]
- property columns: Dict[str, SchemaProperty]
- property notion: Dict[str, Any]