benchling_sdk.apps.framework module¶
- class App¶
Bases:
Generic
[benchling_sdk.apps.framework.ConfigType
]App.
See https://docs.benchling.com/docs/getting-started-benchling-apps
Accepts providers as arguments to lazily initialize since some required attributes may not be known until runtime. Also allows for easier mocking in tests.
- __init__(id: str, benchling_provider: BenchlingProvider, tenant_url_provider: TenantUrlProvider, config_provider: ConfigProvider[benchling_sdk.apps.framework.ConfigType] = attr_dict['_config_provider'].default) None ¶
Method generated by attrs for class App.
- property config: benchling_sdk.apps.framework.ConfigType¶
Return config for the app.
Apps which do not have config will raise MissingAppConfigTypeError.
- continue_session_context(session_id: str, context_enter_handler: Optional[SessionContextEnterHandler[benchling_sdk.apps.framework.AppType]] = None, context_exit_handler: Optional[SessionContextExitHandler[benchling_sdk.apps.framework.AppType]] = None) SessionContextManager[benchling_sdk.apps.framework.AppType] ¶
Continue Session Context.
Fetch an existing app session from Benchling and enter a context with it.
- create_session_context(name: str, timeout_seconds: int, context_enter_handler: Optional[SessionContextEnterHandler[benchling_sdk.apps.framework.AppType]] = None, context_exit_handler: Optional[SessionContextExitHandler[benchling_sdk.apps.framework.AppType]] = None) SessionContextManager[benchling_sdk.apps.framework.AppType] ¶
Create Session Context.
Create a new app session in Benchling.
- classmethod init(id: str, benchling_provider: BenchlingProvider, tenant_url_provider: TenantUrlProvider, config_provider: Optional[ConfigProvider] = None) benchling_sdk.apps.framework.AppType ¶
Init.
Initialize an app from its class.
- reset() None ¶
Reset the app.
Generally clears all states and internal caches, which may cause subsequent invocations of the App to be expensive.
- with_base_url(base_url: str) benchling_sdk.apps.framework.AppType ¶
Create a new copy of the app with a different base URL.
- with_webhook(webhook: Union[dict, WebhookEnvelopeV0]) benchling_sdk.apps.framework.AppType ¶
Create a new copy of the app with a different base URL provided by a webhook.
- class BaseAppFactory¶
Bases:
abc.ABC
,Generic
[benchling_sdk.apps.framework.AppType
,benchling_sdk.apps.framework.ConfigType
]Base App Factory.
Can be used as an alternative to init_app() for those who prefer to import a pre-defined app instance globally. Call create() on the factory to initialize an App.
Users must subclass AppFactory and implement its abstract methods to create a subclass of App.
- __init__(app_type: Type[benchling_sdk.apps.framework.AppType], app_id: str, config_type: Optional[Type[benchling_sdk.apps.framework.ConfigType]] = None)¶
Initialize App Factory.
- abstract property auth_method: benchling_api_client.v2.benchling_client.AuthorizationMethod¶
Get an auth method to pass to Benchling.
Must be implemented on all subclasses.
- benchling_provider: BenchlingProvider¶
- property client_decorator: Optional[BenchlingApiClientDecorator]¶
Get a BenchlingApiClientDecorator for Benchling.
- config_provider: ConfigProvider[benchling_sdk.apps.framework.ConfigType]¶
- create() benchling_sdk.apps.framework.AppType ¶
Create an App instance from the factory.
- property decryption_provider: Optional[BaseDecryptionProvider]¶
Get a decryption provider for decryption app config secrets.
- property httpx_client: Optional[httpx.Client]¶
Get a custom httpx Client for Benchling.
- property retry_strategy: RetryStrategy¶
Get a RetryStrategy for Benchling.
- property tenant_url_provider: TenantUrlProvider¶
Get a tenant URL provider that will provide a base URL for Benchling at runtime.
By default, assumes that the App has no base_url and will be provided one later (e.g., from a webhook). Invoking app.benchling on an App in this state without setting a URL will raise an error.
Use tenant_url_provider_static(âhttps://myurlâ¦â) to specify a single URL.
- class ConfigProvider¶
Bases:
Protocol
[benchling_sdk.apps.framework.ConfigType
]Return a ConfigType instance.
- __init__(*args, **kwargs)¶
- exception MalformedAppWebhookError¶
Bases:
Exception
Error when a webhook cannot be read by an app.
- exception MissingAppConfigTypeError¶
Bases:
Exception
Error when app config is expected but unspecified.
- exception MissingTenantUrlProviderError¶
Bases:
Exception
Error when a base URL is expected but unspecified.
- benchling_provider_static(benchling: Benchling) BenchlingProvider ¶
Create a provider function that always returns a static Benchling.
- config_provider_error_on_call() ConfigProvider[benchling_sdk.apps.framework.ConfigType] ¶
Create a provider function that raises an error.
Used as a ConfigProvider for apps which donât support config and donât expect to invoke it.
- config_provider_static(config: benchling_sdk.apps.framework.ConfigType) ConfigProvider[benchling_sdk.apps.framework.ConfigType] ¶
Create a provider function that always returns a static app config.
- init_app(app_id: str, benchling_provider: BenchlingProvider, tenant_url_provider: TenantUrlProvider, config_provider: Optional[ConfigProvider[benchling_sdk.apps.framework.ConfigType]] = None) App[benchling_sdk.apps.framework.ConfigType] ¶
Init App.
Initializes a Benchling App with a series of functions to provide App dependencies at runtime.
- init_static_app(app_id: str, benchling: Benchling, config: Optional[benchling_sdk.apps.framework.ConfigType] = None) App[benchling_sdk.apps.framework.ConfigType] ¶
Init Static App.
Initializes a Benchling App with static values. Suitable for apps that communicate with a single URL.
- tenant_url_provider_lazy() TenantUrlProvider ¶
Create a provider function for app that will be initialized at runtime, such as from a webhook.
Useful for when a base_url for Benchling is not known in advance but can be supplied at runtime.
- tenant_url_provider_static(tenant_url: str) TenantUrlProvider ¶
Create a provider function that always returns a static tenant URL.