ORIONIS API REFERENCE

THE ORIONIS API

Build with clarity.

Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.

class documentation

class ICollection(ABC): (source)

Known subclasses: orionis.support.types.Collection

View In Hierarchy

Undocumented

Method all Return all items in the collection.
Method avg Compute the average of the items.
Method chunk Divide the collection into smaller collections of a specified size.
Method collapse Collapse the collection of arrays into a single, flat collection.
Method contains Check if the collection contains a given item.
Method count Return the number of items in the collection.
Method diff Return items not present in the given collection.
Method each Iterate over items and apply the callback to each.
Method every Determine whether all items satisfy the given callback condition.
Method filter Filter items in the collection using a callback.
Method first Return the first item in the collection, optionally filtered by a callback.
Method flatten Flatten the collection into a single dimension.
Method forget Remove items from the collection by their keys.
Method forPage Slice the collection for pagination.
Method get Retrieve an item from the collection by key.
Method groupBy Group items in the collection by a specified key.
Method implode Join all items in the collection into a single string.
Method isEmpty Check if the collection is empty.
Method last Return the last item in the collection, optionally filtered by a callback.
Method map Apply a function to each item in the collection.
Method mapInto Map items into instances of the given class.
Method max Return the maximum value from the items.
Method merge Merge the collection with the given items.
Method min Return the minimum value from the items.
Method pluck Extract values for a given key from all items.
Method pop Remove and return the last item from the collection.
Method prepend Prepend an item to the beginning of the collection.
Method pull Remove and return an item from the collection by key.
Method push Add an item to the end of the collection.
Method put Insert or update an item in the collection at the specified key.
Method random Return one or more random items from the collection.
Method reduce Reduce the collection to a single value using a callback.
Method reject Reject items that pass a given truth test.
Method reverse Reverse the order of items in the collection.
Method serialize Serialize the collection items as a list.
Method setAppends Set the attributes to append to the Collection.
Method shift Remove and return the first item from the collection.
Method sort Sort the items in the collection.
Method sum Compute the sum of the given values.
Method take Take a specific number of items from the collection.
Method toJson Return the collection items as a JSON string.
Method transform Transform each item in the collection using a callback.
Method unique Return unique items from the collection.
Method where Filter items by a given key-value pair or comparison.
Method whereIn Filter items where a given key's value is in a list of values.
Method whereNotIn Filter items where a given key's value is not in a list of values.
Method zip Zip the collection with the given items by index.

Return all items in the collection.

Returns
list of AnyAll items contained in the collection.
def avg(self, key: str | None = None) -> float: (source)

Compute the average of the items.

Parameters
key:str | None, optionalThe key to use for calculating the average of values. If None, use all items.
Returns
floatThe average value of the items. Returns 0 if calculation fails.
def chunk(self, size: int) -> ICollection: (source)

Divide the collection into smaller collections of a specified size.

Parameters
size:intNumber of items in each chunk.
Returns
CollectionA new Collection containing sub-collections (chunks) of the specified size.
def collapse(self) -> ICollection: (source)

Collapse the collection of arrays into a single, flat collection.

Returns
CollectionA new Collection containing all items from nested arrays, flattened.
def contains(self, key: str | Callable, value: object = None) -> bool: (source)

Check if the collection contains a given item.

Parameters
key:str or CallableThe key to check for, or a callback function.
value:Any, optionalThe value to match when key is a string, by default None.
Returns
boolTrue if the item is found, False otherwise.
def count(self) -> int: (source)

Return the number of items in the collection.

Returns
intThe number of items in the collection.

Return items not present in the given collection.

Parameters
items:list[Any] | CollectionThe items to compare against.
Returns
CollectionA new collection containing items not found in the provided collection.
def each(self, callback: Callable) -> ICollection: (source)

Iterate over items and apply the callback to each.

Parameters
callback:CallableThe callback function to apply to each item.
Returns
CollectionThe current collection instance.
def every(self, callback: Callable) -> bool: (source)

Determine whether all items satisfy the given callback condition.

Parameters
callback:CallableThe callback function to test each item.
Returns
boolTrue if all items pass the test, otherwise False.
def filter(self, callback: Callable) -> ICollection: (source)

Filter items in the collection using a callback.

Parameters
callback:CallableFunction to determine if an item should be included.
Returns
CollectionA new Collection containing items for which the callback returns True.
def first(self, callback: Callable | None = None) -> object: (source)

Return the first item in the collection, optionally filtered by a callback.

Parameters
callback:Callable | None, optionalA function to filter items before returning the first one, by default None.
Returns
objectThe first item in the filtered collection, or None if empty.

Flatten the collection into a single dimension.

Returns
CollectionA new Collection containing all items, flattened to a single dimension.
def forget(self, *keys: int | str) -> ICollection: (source)

Remove items from the collection by their keys.

Parameters
*keys:AnyThe keys of the items to remove from the collection.
Returns
CollectionThe current collection instance after removal.
def forPage(self, page: int, number: int) -> ICollection: (source)

Slice the collection for pagination.

Parameters
page:intThe page number to retrieve.
number:intThe number of items per page.
Returns
CollectionA new Collection containing the paginated items.
def get(self, key: int | str, default: object = None) -> object: (source)

Retrieve an item from the collection by key.

Parameters
key:AnyThe key or index to retrieve from the collection.
default:Any, optionalThe value to return if the key is not found. Defaults to None.
Returns
AnyThe item at the specified key, or the default value if not found.
def groupBy(self, key: str) -> ICollection: (source)

Group items in the collection by a specified key.

Parameters
key:strThe key to group items by.
Returns
CollectionA new Collection instance containing a dictionary where each key is a unique value from the specified key, and each value is a list of items sharing that key.
def implode(self, glue: str = ',', key: str | None = None) -> str: (source)

Join all items in the collection into a single string.

Parameters
glue:str, optionalString used to join the items. Default is ",".
key:str | None, optionalKey to extract from each item before joining. Default is None.
Returns
strA string with all items joined by the specified glue.
def isEmpty(self) -> bool: (source)

Check if the collection is empty.

Returns
boolTrue if the collection is empty, otherwise False.
def last(self, callback: Callable | None = None) -> object: (source)

Return the last item in the collection, optionally filtered by a callback.

Parameters
callback:Callable | None, optionalFunction to filter items before returning the last one, by default None.
Returns
objectThe last item in the filtered collection, or raises IndexError if empty.
def map(self, callback: Callable) -> ICollection: (source)

Apply a function to each item in the collection.

Parameters
callback:CallableFunction to apply to each item.
Returns
CollectionA new Collection containing the mapped items.
def mapInto(self, cls: type, method: str | None = None, **kwargs: object) -> ICollection: (source)

Map items into instances of the given class.

Parameters
cls:typeThe class to map items into.
method:str | None, optionalThe method to call on the class, by default None.
**kwargs:AnyAdditional keyword arguments to pass to the constructor or method.
Returns
CollectionA new collection with the mapped instances.
def max(self, key: str | None = None) -> object: (source)

Return the maximum value from the items.

Parameters
key:str | None, optionalThe key to use for finding the maximum value. If None, use all items.
Returns
objectThe maximum value found, or 0 if not found or on error.

Merge the collection with the given items.

Parameters
items:list[Any] | CollectionThe items to merge into the collection.
Returns
CollectionThe current collection instance with merged items.
Raises
TypeErrorIf items cannot be merged due to incompatible types.
def min(self, key: str | None = None) -> object: (source)

Return the minimum value from the items.

Parameters
key:str | None, optionalThe key to use for finding the minimum value. If None, use all items.
Returns
objectThe minimum value found, or 0 if not found or on error.
def pluck(self, value: str, key: str | None = None) -> ICollection: (source)

Extract values for a given key from all items.

Parameters
value:strThe key to extract from each item.
key:str | None, optionalThe key to use as the result key, by default None.
Returns
CollectionA new collection containing the plucked values.

Remove and return the last item from the collection.

Returns
AnyThe last item from the collection.
def prepend(self, value: object) -> ICollection: (source)

Prepend an item to the beginning of the collection.

Parameters
value:AnyThe value to prepend to the collection.
Returns
CollectionThe current collection instance with the new item prepended.
def pull(self, key: int | str) -> object: (source)

Remove and return an item from the collection by key.

Parameters
key:AnyThe key of the item to remove.
Returns
AnyThe removed item, or None if not found.
def push(self, value: object) -> ICollection: (source)

Add an item to the end of the collection.

Parameters
value:AnyThe value to add to the collection.
Returns
CollectionThe current collection instance with the new item appended.
def put(self, key: int | str, value: object) -> ICollection: (source)

Insert or update an item in the collection at the specified key.

Parameters
key:AnyThe key or index at which to set the value.
value:AnyThe value to assign at the specified key.
Returns
CollectionThe current collection instance with the updated item.
def random(self, count: int | None = None) -> object | ICollection | None: (source)

Return one or more random items from the collection.

Parameters
count:int | None, optionalThe number of items to return. If None, returns a single item.
Returns
Any | Collection | NoneA single random item if count is None, a Collection if count is given, or None if the collection is empty.
Raises
ValueErrorIf count is greater than the number of items in the collection.
def reduce(self, callback: Callable, initial: object = 0) -> object: (source)

Reduce the collection to a single value using a callback.

Parameters
callback:CallableThe function to apply cumulatively to the items.
initial:Any, optionalThe initial value to start the reduction, by default 0.
Returns
AnyThe reduced value after applying the callback.
def reject(self, callback: Callable) -> ICollection: (source)

Reject items that pass a given truth test.

Parameters
callback:CallableThe callback function to test items.
Returns
CollectionThe current collection instance with items not passing the test.

Reverse the order of items in the collection.

Returns
CollectionThe current collection instance with items in reversed order.
def serialize(self) -> list[Any]: (source)

Serialize the collection items as a list.

Returns
list of AnyThe serialized items in the collection.
def setAppends(self, appends: list[str]) -> ICollection: (source)

Set the attributes to append to the Collection.

Parameters
appends:list[str]The attributes to append.
Returns
CollectionThe current collection instance.
def shift(self) -> object: (source)

Remove and return the first item from the collection.

Returns
AnyThe first item from the collection, or None if the collection is empty.
def sort(self, key: str | None = None) -> ICollection: (source)

Sort the items in the collection.

Parameters
key:str | None, optionalThe key to sort by. If None, sort items directly.
Returns
CollectionThe current collection instance with sorted items.
def sum(self, key: str | None = None) -> float: (source)

Compute the sum of the given values.

Parameters
key:str | None, optionalThe key to sum by. If None, sum all items.
Returns
floatThe sum of the values. Returns 0 if calculation fails.
def take(self, number: int) -> ICollection: (source)

Take a specific number of items from the collection.

Parameters
number:intThe number of items to take. If negative, takes from the end.
Returns
CollectionA new Collection containing the specified number of items.
def toJson(self, **kwargs: object) -> str: (source)

Return the collection items as a JSON string.

Parameters
**kwargs:AnyAdditional arguments to pass to json.dumps.
Returns
strJSON representation of the serialized collection items.
def transform(self, callback: Callable) -> ICollection: (source)

Transform each item in the collection using a callback.

Parameters
callback:CallableThe callback function to transform items.
Returns
CollectionThe current collection instance with transformed items.
def unique(self, key: str | None = None) -> ICollection: (source)

Return unique items from the collection.

Parameters
key:str | None, optionalThe key to use for uniqueness comparison. If None, use items directly.
Returns
CollectionA new Collection containing only unique items.
def where(self, key: str, *args: object) -> ICollection: (source)

Filter items by a given key-value pair or comparison.

Parameters
key:strThe key to filter by.
*args:AnyThe operator and value, or just the value.
Returns
CollectionA new Collection instance containing filtered items.
def whereIn(self, key: str, values: list[Any] | ICollection) -> ICollection: (source)

Filter items where a given key's value is in a list of values.

Parameters
key:strThe key to filter by.
values:list[Any] | CollectionThe list of values to check against.
Returns
CollectionA new collection containing items where the key's value is in values.
def whereNotIn(self, key: str, values: list[Any] | ICollection) -> ICollection: (source)

Filter items where a given key's value is not in a list of values.

Parameters
key:strThe key to filter by.
values:list[Any] | CollectionThe list of values to check against.
Returns
CollectionA new Collection containing items where the key's value is not in values.

Zip the collection with the given items by index.

Parameters
items:list[Any] | CollectionThe items to zip with.
Returns
CollectionA new Collection containing pairs of items from both collections.
Raises
ValueErrorIf the 'items' parameter is not a list or Collection.