Cas
albert.collections.cas.CasCollection
Bases: BaseCollection
Manage CAS entries in the Albert platform.
A CAS entry (Cas) records a chemical substance
identified by its CAS Registry Number (e.g. "7727-37-9" for nitrogen). CAS
entries are the shared chemical dictionary that raw-material Inventory Items
point to: a raw material lists the CAS numbers of its constituents, each paired
with an amount (see CasAmount).
CAS entries are referenced by their CAS ID (format CAS..., e.g. "CAS1").
Most workflows either look a substance up by its registry number
(get_by_number) or ensure one exists before linking it
(get_or_create).
This collection is accessed as client.cas.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base API route for CAS requests. |
Methods:
| Name | Description |
|---|---|
create |
Create a new CAS entry from a registry number or Cas object. |
get_or_create |
Return the existing entry for a registry number, or create it. |
get_by_id |
Get a single CAS entry by its ID. |
get_by_number |
Get a CAS entry by its registry number. |
get_all |
Iterate over CAS entries, optionally filtered by number(s) or ID. |
exists |
Check whether a CAS entry with the given number exists. |
update |
Update an existing CAS entry. |
delete |
Delete a CAS entry by its ID. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/cas.py
get_all
get_all(
*,
number: str | None = None,
cas: list[str] | None = None,
id: CasId | None = None,
order_by: OrderBy = DESCENDING,
start_key: str | int | None = None,
max_items: int | None = None,
) -> Iterator[Cas]
Iterate over CAS entries, optionally filtered.
Use this to list CAS entries or to search by one or more registry numbers.
Results are streamed page by page, so you can iterate large result sets
without loading everything at once. To fetch a single entry when you
already know its registry number or CAS ID, prefer get_by_number
or get_by_id.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
Filter by a single CAS registry number (substring/partial match). |
None
|
cas
|
list[str]
|
Filter by an exact list of CAS registry numbers. |
None
|
id
|
CasId
|
Return only the entry with this CAS ID (format |
None
|
order_by
|
OrderBy
|
Sort direction. Defaults to |
DESCENDING
|
start_key
|
str or int
|
Pagination resume key. For unfiltered listing, pass the string key
returned by a previous page. For filtered search ( |
None
|
max_items
|
int
|
Maximum number of entries to yield in total. If None, iterates over all matching entries. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[Cas]
|
Matching CAS entries. On the filtered and unfiltered paths, |
Source code in src/albert/collections/cas.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
exists
Check whether a CAS entry exists for the given registry number.
Useful before creating an entry to avoid duplicates. To retrieve the
matching entry itself (rather than a boolean), use get_by_number;
to fetch-or-create in one step, use get_or_create.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
The CAS registry number to check. |
required |
exact_match
|
bool
|
When True (default), require an exact registry-number match. When
False, treat |
True
|
max_items
|
int
|
Maximum number of results to search through when |
50
|
Returns:
| Type | Description |
|---|---|
bool
|
True if a matching CAS entry exists, False otherwise. |
Source code in src/albert/collections/cas.py
create
Create a new CAS entry.
Use this to add a substance to Albert's CAS dictionary. If you are not
sure whether the substance already exists, prefer get_or_create,
which avoids creating a duplicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cas
|
str or Cas
|
The CAS registry number, or a fully built
|
required |
Returns:
| Type | Description |
|---|---|
Cas
|
The newly created entry, populated with its assigned CAS ID. |
Source code in src/albert/collections/cas.py
get_or_create
Return the CAS entry for a registry number, creating it if needed.
This is the safest way to obtain a CAS entry to link to a raw material:
it looks up the registry number with an exact match and returns the
existing entry if found, otherwise creates a new one via create.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cas
|
str or Cas
|
The CAS registry number, or a fully built
|
required |
Returns:
| Type | Description |
|---|---|
Cas
|
The existing or newly created entry. |
Source code in src/albert/collections/cas.py
get_by_id
Get a single CAS entry by its ID.
To look a substance up by its registry number instead, use
get_by_number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
CasId
|
The CAS ID to retrieve (format |
required |
Returns:
| Type | Description |
|---|---|
Cas
|
The fully populated CAS entry. |
Source code in src/albert/collections/cas.py
get_by_number
get_by_number(
*,
number: str,
exact_match: bool = True,
max_items: int | None = 50,
) -> Cas | None
Get a CAS entry by its registry number.
The number is normalized before matching (extra spaces around the dashes
are removed), mirroring how the Albert backend compares CAS numbers. To
fetch-or-create in one step, use get_or_create.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
The CAS registry number to retrieve. |
required |
exact_match
|
bool
|
When True (default), return the entry whose registry number matches
exactly. When False, return the first entry whose number contains
|
True
|
max_items
|
int
|
Maximum number of results to search through when |
50
|
Returns:
| Type | Description |
|---|---|
Cas or None
|
The matching CAS entry, or None if no match is found. |
Source code in src/albert/collections/cas.py
delete
delete(*, id: CasId) -> None
Delete a CAS entry by its CAS ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
CasId
|
The CAS ID to delete (format |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/cas.py
update
Update an existing CAS entry.
Fetch the entry (e.g. with get_by_id or get_by_number),
modify the updatable fields on the returned object, then pass it here. The
entry is matched by its id, so that field must be set.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
updated_object
|
Cas
|
The modified CAS entry. Must carry the |
required |
Returns:
| Type | Description |
|---|---|
Cas
|
The updated entry as it appears in Albert after the change. |
Notes
Only the following fields are updatable: description, metadata,
notes, smiles. Changes to other fields are ignored.