Skip to main content
A book holds shared risk facts as a collection of related tables. Create CSV files for your risks, then load the folder into Relativities.

Create the tables

This personal auto example uses ppa.SCHEMA. Other line schemas define their own requirements: ho.SCHEMA for homeowners, bop.SCHEMA for businessowners, gl.SCHEMA for monoline general liability and pet.SCHEMA for pet health. A bop or gl book needs only submissions and locations, and a pet book only submissions and pets. For other lines, define your own schema with Schema, Table and Column. Start with submissions, drivers, and vehicles. Add coverages for the coverages you want to price. Match IDs across the files to connect their rows. Create the my-book/ folder with these files:
These files describe one policy, one driver, and one vehicle for a six-month term. Blank cells represent missing values.
my-book/submissions.csv
my-book/drivers.csv
my-book/vehicles.csv
my-book/coverages.csv
The personal auto schema lists the available columns and coverage codes.

Load the book

Read the my-book/ folder with the personal auto schema:
Relativities preserves IDs and postal codes as text and reads core numbers exactly. It creates the policies table from your policy IDs.
To prepare tables in pandas before creating the book, use the constructor:
Read IDs and postal codes as text to preserve leading zeros.
Omitting schema creates a plain book that keeps your tables and their existing types. It infers keys from populated _id columns where possible.A plain book accepts your own table structure; insurance-specific requirements come from an explicit line schema. book.schema describes the observed columns and inferred keys.Program.rate requires an explicit schema. Use a built-in schema or define your own as shown below.

Check the book

Inspect any cell problems:
Structural problems raise BookError. Some invalid cells become blank and appear in book.problems, with suggested corrections; their submissions receive invalid_book when rated. To refuse a book with any problem, pass strict=True. The book raises one BookError that lists each bad cell with each missing table, column and key:
Book.read_csv takes strict too. A strict book holds only rows that fit the schema, so each submission reaches prepare. Store reported facts and leave unknown facts blank. Each program determines which facts it needs for rating. To save the book to another folder, use book.to_csv("checked-book/").

Define your own schema

Save the schema in a module that your books and programs share:
study_schema.py
Each schema includes policies and submissions. Each submission requires a policy_id and at least one risk row. Declare more submission columns with "submissions": Table(("submission_id",), columns, required=True). A reference uses every key column of its target within each submission. Partial references raise BookError. Table.one_of and Table.key_values add row-level rules; the reference lists them. minimum and maximum bound an int, number or date column, and each bound is inclusive. A value outside the range is a problem, like a value of the wrong type. Create a book with the schema:
Construct each Program with the same SCHEMA. To store a Study, save and reload the book first:
import_path names the schema object that Study.from_json imports, so keep that module available. with_columns and with_tables extend a schema in memory only. Model a commercial book applies a custom schema to payroll by state and class.

Read the schema from a JSON document

To share a schema with other tools, write it as a JSON Schema document. The document is an object whose properties are the book’s tables. Each table is an array of rows, with its key in x-key:
equipment.schema.json
Read it with Schema.from_json_schema:
The result is a Schema, so books and programs use it as they use any other schema. Each column reads type, enum, format, the bounds, x-unit and description. Any other rule, such as pattern, raises ValueError. The reference lists each keyword.

Next step

Load a program, then rate your book.