-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7841878
commit 00129a5
Showing
8 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## BenchlingService: [class](https://github.com/dynotx/liminal-orm/blob/main/liminal/connection/benchling_service.py) | ||
|
||
The BenchlingService class takes in a BenchlingConnection object and is used to directly interact with Benchling's SDK, internal API, and Postgres warehouse. This class is surfaced for users so that there is one standard interface for interacting with Benchling around your codebase. Liminal's BenchlingService handles all session management and is a subclass of Benchling's SDK, so all functionality of Benchling's SDK is available. | ||
|
||
BenchlingService can be used to build on top of Liminal's ORM. Below is an example of how to use the BenchlingService class. | ||
|
||
```python | ||
from liminal.connection import BenchlingConnection | ||
from liminal.connection import BenchlingService | ||
|
||
connection = BenchlingConnection( | ||
... | ||
) | ||
benchling_service = BenchlingService(connection, use_internal_api=True, use_warehouse=True) # enable all connections | ||
|
||
# Use Benchling SDK | ||
entity = benchling_service.custom_entities.get_by_id("my-entity-id") | ||
|
||
# Use to query Postgres warehouse using SQLAlchemy | ||
with benchling_service() as session: | ||
entity = session.query(Pizza).all() | ||
``` | ||
|
||
### Parameters | ||
|
||
**connection: BenchlingConnection** | ||
|
||
> The connection object that contains the credentials for the Benchling tenant. | ||
**use_api: bool** | ||
|
||
> Whether to connect to the Benchling SDK. Defaults to True. (See Benchling SDK documentation [here](https://docs.benchling.com/docs/getting-started-with-the-sdk)) | ||
**use_internal_api: bool** | ||
|
||
> Whether to connect to the Benchling internal API. Defaults to False. | ||
**use_warehouse: bool** | ||
|
||
> Whether to connect to the Benchling Postgres warehouse. Defaults to False. See SQLAlchemy documentation [here](https://www.sqlalchemy.org/) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## Benchling Base Validator: [class](https://github.com/dynotx/liminal-orm/blob/main/liminal/validation/__init__.py) | ||
|
||
Below is an example of a Benchling Validator defined in Liminal for validating the cook temp of a pizza. | ||
|
||
```python | ||
from liminal.validation import BenchlingValidator, BenchlingValidatorReport, BenchlingReportLevel | ||
from liminal.orm.base_model import BaseModel | ||
|
||
class CookTempValidator(BenchlingValidator): | ||
"""Validates that a field value is a valid enum value for a Benchling entity""" | ||
|
||
def validate(self, entity: type[BaseModel]) -> BenchlingValidatorReport: | ||
valid = True | ||
if entity.cook_time is not None and entity.cook_temp is None: | ||
valid = False | ||
return self.create_report(valid, BenchlingReportLevel.MED, entity, "Cook temp is required if cook time is set") | ||
if entity.cook_time is None and entity.cook_temp is not None: | ||
valid = False | ||
return self.create_report(valid, BenchlingReportLevel.MED, entity, "Cook time is required if cook temp is set") | ||
return self.create_report(valid, BenchlingReportLevel.MED, entity, None) | ||
``` | ||
|
||
A `validate(entity)` function is required to be defined in the BenchlingValidator subclass. This function should contain the logic to validate the entity. The function should return a `BenchlingValidatorReport` object, which can be easily created using the `create_report` method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters