Attachments
albert.collections.attachments.AttachmentCollection
Bases: BaseCollection
AttachmentCollection manages Attachment entities in the Albert platform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The Albert session instance. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base URL for attachment API requests. |
Methods:
| Name | Description |
|---|---|
get_by_id |
Retrieve an attachment by its ID. |
create |
Create a new attachment. |
delete |
Delete an attachment by its ID. |
update |
Update an existing attachment. |
get_by_parent_ids |
Retrieve attachments grouped by parent ID. |
get_jurisdiction_codes |
List available jurisdiction codes. |
get_language_codes |
List available language codes. |
attach_file_to_note |
Attach an already-uploaded file to a note. |
upload_and_attach_file_to_note |
Upload a file and attach it to a note. |
upload_and_attach_sds_to_inventory_item |
Upload an SDS document and attach it to an inventory item. |
upload_and_attach_document_to_inventory_item |
Upload a document and attach it to an inventory item. |
upload_and_attach_document_to_project |
Upload a file and attach it as a document to a project. |
Source code in src/albert/collections/attachments.py
get_by_id
get_by_id(*, id: AttachmentId) -> Attachment
Retrieves an attachment by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
AttachmentId
|
The ID of the attachment to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Attachment
|
The Attachment object corresponding to the provided ID. |
Source code in src/albert/collections/attachments.py
create
create(*, attachment: Attachment) -> Attachment
Create a new attachment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attachment
|
Attachment
|
The attachment to create. |
required |
Returns:
| Type | Description |
|---|---|
Attachment
|
The created attachment. |
Source code in src/albert/collections/attachments.py
update
update(*, attachment: Attachment) -> Attachment
Update an attachment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attachment
|
Attachment
|
The attachment with updated fields. Must include |
required |
Returns:
| Type | Description |
|---|---|
Attachment
|
The updated Attachment. |
Notes
The following fields can be updated: name, parent_id, revision_date.
Source code in src/albert/collections/attachments.py
get_by_parent_ids
get_by_parent_ids(
*,
parent_ids: list[str],
data_column_ids: list[DataColumnId] | None = None,
) -> dict[str, list[Attachment]]
Retrieves attachments by their parent IDs.
Note: This method returns a dictionary where the keys are parent IDs and the values are lists of Attachment objects associated with each parent ID. If the parent ID has no attachments, it will not be included in the dictionary.
If no attachments are found for any of the provided parent IDs, the API response will be an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_ids
|
list[str]
|
Parent IDs of the objects to which the attachments are linked. IDs must
include the full entity prefix (e.g. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[Attachment]]
|
A dictionary mapping parent IDs to lists of Attachment objects associated with each parent ID. |
Source code in src/albert/collections/attachments.py
attach_file_to_note
attach_file_to_note(
*,
note_id: str,
file_name: str,
file_key: str,
category: FileCategory = OTHER,
) -> Attachment
Attaches an already uploaded file to a note.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note_id
|
str
|
The ID of the note to attach the file to. |
required |
file_name
|
str
|
The name of the file to attach. |
required |
file_key
|
str
|
The unique key of the file to attach (the returned upload name). |
required |
category
|
FileCategory
|
The type of file, by default FileCategory.OTHER |
OTHER
|
Returns:
| Type | Description |
|---|---|
Attachment
|
The related attachment object. |
Source code in src/albert/collections/attachments.py
get_jurisdiction_codes
Return available jurisdiction codes.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Mapping of jurisdiction name to code (e.g. |
Source code in src/albert/collections/attachments.py
get_language_codes
Return available language codes.
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Mapping of language name to code (e.g. |
Source code in src/albert/collections/attachments.py
delete
delete(*, id: AttachmentId) -> None
Deletes an attachment by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the attachment to delete. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/attachments.py
upload_and_attach_file_as_note
upload_and_attach_file_as_note(
parent_id: str,
file_data: IO,
note_text: str = "",
file_name: str = "",
upload_key: str | None = None,
) -> Note
Uploads a file and attaches it to a new note. A user can be tagged in the note_text string by using f-string and the User.to_note_mention() method. This allows for easy tagging and referencing of users within notes. example: f"Hello {tagged_user.to_note_mention()}!"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_id
|
str
|
The ID of the parent entity onto which the note will be attached. |
required |
file_data
|
IO
|
The file data to upload. |
required |
note_text
|
str
|
Any additional text to add to the note, by default "" |
''
|
file_name
|
str
|
The name of the file. Include a file extension to infer the content type;
otherwise, the upload defaults to |
''
|
upload_key
|
str | None
|
Override the storage key used when signing and uploading the file.
Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Note
|
The created note. |
Source code in src/albert/collections/attachments.py
upload_and_attach_sds_to_inventory_item
upload_and_attach_sds_to_inventory_item(
*,
inventory_id: InventoryId,
file_sds: Path,
revision_date: date,
storage_class: str,
un_number: str,
jurisdiction_code: str = "US",
language_code: str = "EN",
hazard_statements: list[HazardStatement] | None = None,
hazard_symbols: list[HazardSymbol] | None = None,
wgk: str | None = None,
) -> Attachment
Upload an SDS document and attach it to an inventory item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inventory_id
|
str
|
Id of Inventory Item to attach SDS to. |
required |
file_sds
|
Path
|
Local path to the SDS PDF to upload. |
required |
revision_date
|
date
|
Revision date for the SDS. (yyyy-mm-dd) |
required |
un_number
|
str
|
The UN number. |
required |
storage_class
|
str
|
The Storage Class number. |
required |
jurisdiction_code
|
str
|
Jurisdiction code for the SDS (e.g. |
'US'
|
language_code
|
str
|
Language code for the SDS (e.g. |
'EN'
|
hazard_statements
|
list[HazardStatement] | None
|
Collection of hazard statements. |
None
|
hazard_symbols
|
list[HazardSymbol] | None
|
Collection of hazard symbols. |
None
|
wgk
|
str | None
|
WGK classification metadata. |
None
|
Returns:
| Type | Description |
|---|---|
Attachment
|
The created SDS attachment linked to the inventory item. |
Source code in src/albert/collections/attachments.py
upload_and_attach_document_to_inventory_item
upload_and_attach_document_to_inventory_item(
*,
inventory_id: InventoryId,
file_path: Path,
category: AttachmentCategory | str,
revision_date: date | None = None,
description: str | None = None,
jurisdiction_code: str | None = None,
language_code: str | None = None,
hazard_statements: list[HazardStatement] | None = None,
hazard_symbols: list[HazardSymbol] | None = None,
un_number: str | None = None,
storage_class: str | None = None,
wgk: str | None = None,
) -> Attachment
Upload a file and attach it as a document to an inventory item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inventory_id
|
str
|
The Albert ID of the inventory item (e.g. |
required |
file_path
|
Path
|
Local path to the file to upload. |
required |
category
|
AttachmentCategory | str
|
Document category. |
required |
revision_date
|
date | None
|
Revision date for the document. |
None
|
description
|
str | None
|
Description for the document. |
None
|
jurisdiction_code
|
str | None
|
Jurisdiction code (e.g. |
None
|
language_code
|
str | None
|
Language code (e.g. |
None
|
hazard_statements
|
list[HazardStatement] | None
|
Hazard statements to associate with the document. |
None
|
hazard_symbols
|
list[HazardSymbol] | None
|
Hazard symbols to associate with the document. |
None
|
un_number
|
str | None
|
UN number. |
None
|
storage_class
|
str | None
|
Storage class. |
None
|
wgk
|
str | None
|
Water hazard class (WGK). |
None
|
Returns:
| Type | Description |
|---|---|
Attachment
|
The created attachment linked to the inventory item. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
Source code in src/albert/collections/attachments.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | |
upload_and_attach_document_to_project
upload_and_attach_document_to_project(
*, project_id: ProjectId, file_path: Path
) -> Attachment
Upload a file and attach it as a document to a project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
ProjectId
|
The Albert ID of the project (e.g. |
required |
file_path
|
Path
|
Local path to the file to upload. |
required |
Returns:
| Type | Description |
|---|---|
Attachment
|
The created attachment record. |