BerryDB¶
- static BerryDB.init(host)¶
Initializes the SDK with the given host, which can be an IPv4 address or a domain name, optionally including a port. If no scheme (http/https) is provided, “https://” is prefixed by default.
Parameters:
host (str): The host address of your BerryDB instance. Examples: “https://my-berrydb.com”, “my-berrydb:8080”, “192.168.1.1”, “192.168.1.1:8080”
Returns:
None
Raises:
ValueError: If the host is invalid or uses an unsupported scheme.
Example:
# import BerryDB from berrydb import BerryDB BerryDB.init("app.berrydb.io")
- classmethod BerryDB.connect(api_key, database_name, bucket_name='BerryDb')¶
This method establishes a connection to the specified database. The connection uses the provided api_key for authentication and allows you to interact with the database referenced by database_name.
Tip
You can find your BerryDB api_key here.
An organization is defined by the domain in the email-id used when creating your BerryDB account. For example, if the account is registered with the email address
john@tatooine.com
, the corresponding organization will betatooine.com
.Once the connection is established, you will receive a database connection object. This object can be used to perform further operations, such as querying, inserting/updating data within the connected database.
Parameters:
api_key (str): API Key for authentication.
database_name (str): Name of the database to connect.
Note
database_name
cannot contain-
(hyphens) and can only contain the following characters:A-Z
,a-z
,0-9
,#
,_
, and must start with a letter. It should be between 1 and 128 characters long.Returns:
Database: An instance of the database.
None: If the database does not exist in the organization.
Example:
from berrydb import BerryDB berrydb_api_key = "BERRYDB_API_KEY" database_name = "myNewDatabase" database = BerryDB.connect(berrydb_api_key, database_name)
- classmethod BerryDB.databases(api_key)¶
The databases method retrieves a list of all databases accessible to the organization associated with the provided API key. Each database is represented as a dictionary containing relevant metadata about that database, such as its name, ID, creation date, and other associated properties.
This method is essential for listing the databases available in your organization, making it easier to interact with them for further operations like querying, updating, or deleting records.
Parameters:
api_key (str): API Key for authentication.
Returns:
List[Dict]
: A list where each entry is a dictionary representing a database.
Example:
# import BerryDB from berrydb import BerryDB berrydb_api_key = "BERRYDB_API_KEY" db_list = BerryDB.databases(berrydb_api_key) print("List of Databases in the organization: ", db_list)
- classmethod BerryDB.create_schema(api_key, schema_name, schema_desc, schema_details)¶
The
create_schema
method is used to define and create a new schema for a database. This schema provides a structured way to store data, including specifying data types, filterable fields, indexable fields, and other metadata. Schemas are shared resources accessible to all members of the organization. Create the right schema required for your use case. BerryDB supports schema evolution. You can always add new fields and change your schema without impacting your app. (Support for editing schemas within the SDK is planned for future releases. Currently, you can edit schemas using the Web App.)Parameters:
api_key (
str
): The API Key used for authentication. This key must belong to the user creating the schema.schema_name (
str
): The name of the schema being created. It should be a unique within the organization.schema_desc (
str
): A brief description of the schema, which explains its purpose.schema_details (
Dict
): A dictionary that defines the structure of the schema. This includes fields, data types, indexing, filtering, and more. The schema consists of:schemaName (
str
): The name of the schema.userId (
str
): The ID of the user creating the schema.userEmail (
str
): The email of the user.rawSchema (
Dict[str, any]
): A dictionary that outlines the fields and data structure for the schema. This includes nested objects and arrays.schemaDataTypes (
Dict[str, str]
): A dictionary that specifies the data types for each field in the schema, including nested fields within objects and arrays.filterFields (
List[str]
): An optional list of fields that can be used to filter data within the schema.indexFields (
List[str]
): A list of fields that will be indexed to improve query performance.displayTextField (
str
): The field that represents the main display text for each record. (Optional
)displayImageField (
str
): The field that represents the display image for each record. (Optional
)
Note
schema_name cannot contain -`(Hyphens) and can only contain the following characters: `A-Z a-z 0-9 # _, and must start with a letter, [A-Z a-z]. The length of the schema name should be between 1 and 128. schema_desc length should be between 1 and 256.
Returns:
str: A success message if the schema is created successfully.
None: If there is an error during schema creation, an error message will be printed, and
None
will be returned.
Example:
# import BerryDB from berrydb import BerryDB berrydb_api_key = "BERRYDB_API_KEY" email_id = "EMAIL_ID" db_name = "StudentData" schema_name = "MyNewSchema" schema = { "schemaName": schema_name, "rawSchema": { "profilePic": "", "name": "", "age": 0, "isAlumni": False "addresses": [ { "line1": "", "line2": "", "area": "", "country": "", "zipcode": "" } ] }, "schemaDataTypes": { "profilePic": "string", "name": "string", "age": "number", "isAlumni": "boolean", "addresses": "array", "addresses[0]": "object", "addresses[0].line1": "string", "addresses[0].line2": "string", "addresses[0].area": "string", "addresses[0].country": "string", "addresses[0].zipcode": "string" }, "filterFields": [ "addresses[0].country", "isAlumni" ], "indexFields": [ "name", "addresses[0].area" ], "displayTextField": "name" "displayImageField": "profilePic" } print(BerryDB.create_schema(api_key=berrydb_api_key, schema_name=schema_name, schema_desc="This is a schema to store users and their addresses", schema_details=schema))
- classmethod BerryDB.create_database(api_key, database_name, schema_name, bucket_name='BerryDb')¶
The
create_database
method is used to initialize a new database instance within the BerryDB ecosystem confined to the organization the user belongs to. Similar to the connect method it returns a database connection object. If a database with the specified name already exists, an informative failure message is printed, and the method returns None, preventing any accidental overwrites.Tip
You can find your BerryDB api_key here.
An organization is defined by the domain in the email-id used when creating your BerryDB account. For example, if the account is registered with the email address
john@tatooine.com
, the corresponding organization will betatooine.com
.Databases are shared resources accessible to all members of the organization.
Once the connection is established, you will receive a database connection object. This object can be used to perform further operations, such as querying, inserting/updating data within the connected database.
Parameters:
api_key (
str
): API Key for authentication.database_name (
str
): The unique name for the new database. This identifier will be used to reference the database in future operations. Ensure that the name is distinct from existing databases.schema_name (
str
): The name of the schema that will be applied to the database. This schema dictates the structure of the data, including the fields and their data types, ensuring data consistency and integrity.
Returns:
Database
: An instance of the newly created database.None
: If a database with the provided name already exists, a failure message is printed, andNone
is returned.
Example
# import BerryDB from berrydb import BerryDB # Define your API key and other required parameters berrydb_api_key = "BERRYDB_API_KEY" # Replace with your actual API key database_name = "MyNewDatabase" # Desired name for the new database schema_name = "MySchema" # Name of the schema to apply to the new database # Create a new database database = BerryDB.create_database( api_key=berrydb_api_key, database_name=database_name, schema_name=schema_name )
- classmethod BerryDB.delete_database(api_key, database_name)¶
The
delete_database
method is used to permanently remove a specified database from your organization. This action is irreversible, so it should be used with caution. Upon successful deletion, a confirmation message will be returned.Parameters:
api_key (
str
): API Key for authentication.database_name (
str
): The name of the database you wish to delete. Ensure that the provided name matches exactly with the existing database to avoid errors or unintended deletions.
Returns:
str
: A confirmation message indicating that the database has been successfully deleted.str
: If the deletion fails due to an incorrect database name or if the database does not exist in the , an error message will be returned instead.
Example
# import BerryDB from berrydb import BerryDB # Define your API key and the database name to delete berrydb_api_key = "BERRYDB_API_KEY" # Replace with your actual API key database_name = "MyOldDatabase" # Name of the database to be deleted # Delete the specified database result = BerryDB.delete_database(api_key=berrydb_api_key, database_name=database_name) print(result)
- classmethod BerryDB.create_annotation_project(berrydb_api_key, annotations_api_key, project_name, project_description='')¶
The
create_annotation_project
method is used to create a new Annotations project within BerryDB. Annotations projects are designed to organize and manage data annotation tasks for various datasets. An annotation project is useful for tasks such as Named Entity Recognition, text or image classification, labeling, image captioning, text summarization, object detection, sentiment analysis, and more. It enables you to efficiently label and organize data. Within BerryDB, you can easily sift through the annotated data using queries, filters, or even leverage LLMs (Large Language Models) for more advanced data exploration.Tip
You can find your BerryDB annotations_api_key here. This key is separate from the standard BerryDB API key to maintain distinct roles, allowing non-developers to manage and annotate records independently.
Parameters:
berrydb_api_key (
str
): Your BerryDB API Key.annotations_api_key (
str
): Your BerryDB annotations API Key.project_name (
str
): The name of the project to be created. This name will be used to identify and manage the project within the BerryDB Annotations system. While there are no restrictions on using the same project name within an organization, it is recommended to use unique names to avoid confusion and ensure better project management.project_description (
str
, optional): An optional description for the project. This can be used to provide additional context or information about the project’s goals, data, or purpose. If no description is provided, this field defaults to an empty string.
Returns:
str
: A success or failure message indicating the result of the project creation attempt. A success message will confirm the creation of the project, while a failure message will explain the reason for any errors.
Example
# import BerryDB from berrydb import BerryDB # Define your API key and other required parameters berrydb_api_key = "BERRYDB_API_KEY" # Replace with your actual BerryDB API key annotations_api_key = "ANNOTATIONS_API_KEY" # Replace with your actual annotations API key project_name = "ImageClassification" # Desired name for the new project project_description = "A project for classifying images into different categories." # Optional description # Create a new annotations project my_annotation_project = BerryDB.create_annotation_project( berrydb_api_key=berrydb_api_key, annotations_api_key=annotations_api_key, project_name=project_name, project_description=project_description )
Note
After creating a project you may perform further actions. Refer to:
AnnotationProject
- classmethod BerryDB.model_repo(berrydb_api_key)¶
Provides access to the BerryDB Model Repository.
The Model Repository is the central point for managing models within BerryDB. You can use the returned
ModelRepo
instance to save new models, request models from integrated providers (like HuggingFace, Vertex AI), and retrieve information about existing models.Parameters:
berrydb_api_key (
str
): The API key for authenticating with BerryDB.
Returns:
ModelRepo
: An instance of the Model Repository, allowing interaction with BerryDB’s model management features.
Example:
from berrydb import BerryDB # Initialize BerryDB (if not already done) # BerryDB.init("your-berrydb-host") api_key = "YOUR_BERRYDB_API_KEY" # Get the model repository instance repo = BerryDB.model_repo(api_key) # You can now use the 'repo' object to interact with models, e.g.: # hf_model_config = ModelConfig.huggingface_builder()...build(api_key=api_key)
Note
Refer ModelConfig to learn how to configure models to add them to your model repository.
Refer Model to learn how to save and retrieve predictions from your model repository.