Get your API key from the Structify Dashboard and set it as an environment variable:
Copy
export STRUCTIFY_API_TOKEN="your_api_key"
Then import and initialize the client:
Copy
from structify import Structify# Uses STRUCTIFY_API_TOKEN env var automaticallyclient = Structify()# Or provide explicitlyclient = Structify(api_key="your_api_key")
Create tables for authors and books, plus a relationship between them:
Copy
from structify import Structifyfrom structify.types.table import Table, Propertyfrom structify.types.dataset_descriptor import Relationshipclient = Structify()# Define entity tablestables = [ Table( name="author", description="an individual who wrote a book", properties=[ Property(name="name", description="The name of the author"), Property(name="genre", description="The genre the author typically writes in"), Property(name="birth_year", description="Year the author was born", prop_type="Integer") ] ), Table( name="book", description="a book that has been written", properties=[ Property(name="title", description="The title of the book"), Property(name="publication_year", description="Year published", prop_type="Integer"), Property(name="copies_sold", description="Number of copies sold", prop_type="Integer") ] )]# Define relationshipsrelationships = [ Relationship( name="authored_by", description="Connects a book to its author", source_table="book", target_table="author" )]# Create the datasetclient.datasets.create( name="books", description="Books and their authors", tables=tables, relationships=relationships)
# For each author, find their genre and booksfor author in client.datasets.view_table(dataset="books", table="author"): # Fill in missing properties client.structure.enhance_property( entity_id=author.id, property_name="genre" ) client.structure.enhance_property( entity_id=author.id, property_name="birth_year" ) # Find books they've written client.structure.enhance_relationship( entity_id=author.id, relationship_name="authored_by" )