id
stringlengths
7
77
text
stringlengths
0
3.4k
metadata
dict
astrapy.admin.DataAPIDatabaseAdmin.async_drop_keyspace
Drop (delete) a keyspace from the database. Async version of the method, for use in an asyncio context.
{ "kind": "function", "name": "async_drop_keyspace", "path": "astrapy.admin.DataAPIDatabaseAdmin.async_drop_keyspace", "parameters": [ { "name": "name", "type": "str", "description": "the keyspace to delete. If it does not exist in this database,\nan error is raised.", "default": null, "value": null }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the whole requested\noperation to complete.\nNote that a timeout is no guarantee that the deletion request\nhas not reached the API server.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "dict[str, Any]", "description": "A dictionary of the form {\"ok\": 1} in case of success." }, { "name": null, "type": "dict[str, Any]", "description": "Otherwise, an exception is raised." } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> admin_for_my_db.list_keyspaces()\n['that_other_one', 'default_keyspace']\n>>> asyncio.run(admin_for_my_db.async_drop_keyspace(\n... \"that_other_one\"\n... ))\n{'ok': 1}\n>>> admin_for_my_db.list_keyspaces()\n['default_keyspace']", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.admin.DataAPIDatabaseAdmin.get_database
Create a Database instance out of this class for working with the data in it.
{ "kind": "function", "name": "get_database", "path": "astrapy.admin.DataAPIDatabaseAdmin.get_database", "parameters": [ { "name": "token", "type": "str | TokenProvider | None", "description": "if supplied, is passed to the Database instead of\nthe one set for this object. Useful if one wants to work in\na least-privilege manner, limiting the permissions for non-admin work.\nThis can be either a literal token string or a subclass of\n`astrapy.authentication.TokenProvider`.", "default": "None", "value": "None" }, { "name": "keyspace", "type": "str | None", "description": "an optional keyspace to set in the resulting Database.\nIf not provided, no keyspace is set, limiting what the Database\ncan do until setting it with e.g. a `use_keyspace` method call.", "default": "None", "value": "None" }, { "name": "namespace", "type": "str | None", "description": "an alias for `keyspace`. *DEPRECATED*, removal in 2.0.", "default": "None", "value": "None" }, { "name": "api_path", "type": "str | None", "description": "path to append to the API Endpoint. In typical usage, this\nshould be left to its default of \"\".", "default": "None", "value": "None" }, { "name": "api_version", "type": "str | None", "description": "version specifier to append to the API path. In typical\nusage, this should be left to its default of \"v1\".", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "Database", "description": "A Database object, ready to be used for working with data and collections." } ], "gathered_types": [ "astrapy.authentication.TokenProvider", "astrapy.database.Database" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_db = admin_for_my_db.get_database()\n>>> my_db.list_collection_names()\n['movies', 'another_collection']", "references": null, "note": "creating an instance of Database does not trigger actual creation\nof the database itself, which should exist beforehand.", "implemented_by": null, "attributes": null }
astrapy.admin.DataAPIDatabaseAdmin.get_async_database
Create an AsyncDatabase instance for the database, to be used when doing data-level work (such as creating/managing collections). This method has identical behavior and signature as the sync counterpart `get_database`: please see that one for more details.
{ "kind": "function", "name": "get_async_database", "path": "astrapy.admin.DataAPIDatabaseAdmin.get_async_database", "parameters": [ { "name": "token", "type": "str | TokenProvider | None", "description": null, "default": "None", "value": null }, { "name": "keyspace", "type": "str | None", "description": null, "default": "None", "value": null }, { "name": "namespace", "type": "str | None", "description": null, "default": "None", "value": null }, { "name": "api_path", "type": "str | None", "description": null, "default": "None", "value": null }, { "name": "api_version", "type": "str | None", "description": null, "default": "None", "value": null } ], "returns": [ { "name": null, "type": "AsyncDatabase", "description": null } ], "gathered_types": [ "astrapy.authentication.TokenProvider", "astrapy.database.AsyncDatabase" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.admin.DataAPIDatabaseAdmin.find_embedding_providers
Example (output abridged and indented for clarity): >>> admin_for_my_db.find_embedding_providers() FindEmbeddingProvidersResult(embedding_providers=..., openai, ...) >>> admin_for_my_db.find_embedding_providers().embedding_providers { 'openai': EmbeddingProvider( display_name='OpenAI', models=[ EmbeddingProviderModel(name='text-embedding-3-small'), ... ] ), ... }
{ "kind": "function", "name": "find_embedding_providers", "path": "astrapy.admin.DataAPIDatabaseAdmin.find_embedding_providers", "parameters": [ { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the DevOps API request.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "FindEmbeddingProvidersResult", "description": "A `FindEmbeddingProvidersResult` object with the complete information" }, { "name": null, "type": "FindEmbeddingProvidersResult", "description": "returned by the API about available embedding providers" } ], "gathered_types": [ "astrapy.info.FindEmbeddingProvidersResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.admin.DataAPIDatabaseAdmin.async_find_embedding_providers
Example (output abridged and indented for clarity): >>> admin_for_my_db.find_embedding_providers() FindEmbeddingProvidersResult(embedding_providers=..., openai, ...) >>> admin_for_my_db.find_embedding_providers().embedding_providers { 'openai': EmbeddingProvider( display_name='OpenAI', models=[ EmbeddingProviderModel(name='text-embedding-3-small'), ... ] ), ... }
{ "kind": "function", "name": "async_find_embedding_providers", "path": "astrapy.admin.DataAPIDatabaseAdmin.async_find_embedding_providers", "parameters": [ { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the DevOps API request.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "FindEmbeddingProvidersResult", "description": "A `FindEmbeddingProvidersResult` object with the complete information" }, { "name": null, "type": "FindEmbeddingProvidersResult", "description": "returned by the API about available embedding providers" } ], "gathered_types": [ "astrapy.info.FindEmbeddingProvidersResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload
{ "kind": "module", "name": "transform_payload", "path": "astrapy.transform_payload", "parameters": null, "returns": null, "gathered_types": null, "value": null, "yields": null, "imports": { "annotations": "__future__.annotations", "logging": null, "Any": "typing.Any", "cast": "typing.cast", "httpx": null, "API_RESPONSE": null, "amake_request": null, "make_request": null, "TypedDict": null, "APIRequestError": null, "api_request": null, "async_api_request": null, "async_raw_api_request": null, "raw_api_request": null, "OPS_API_RESPONSE": null, "DEFAULT_DEV_OPS_API_VERSION": null, "DEFAULT_DEV_OPS_AUTH_HEADER": null, "DEFAULT_DEV_OPS_URL": null, "TimeoutInfoWideType": null, "http_methods": null, "to_httpx_timeout": null, "Dict": "typing.Dict", "List": null, "Protocol": null, "Union": null, "datetime": "datetime", "json": null, "time": "time", "Iterable": "typing.Iterable", "__version__": null, "DEFAULT_REDACTED_HEADERS": null, "DEFAULT_TIMEOUT": null, "UUID": "astrapy.ids.UUID", "ObjectId": "astrapy.ids.ObjectId", "uuid1": null, "uuid3": null, "uuid4": null, "uuid5": null, "uuid6": null, "uuid7": null, "uuid8": null, "AstraDB": null, "AstraDBCollection": null, "AsyncAstraDB": null, "AsyncAstraDBCollection": null, "logger": null, "AstraDBOps": null, "asyncio": null, "warnings": null, "ThreadPoolExecutor": null, "TracebackType": null, "TYPE_CHECKING": null, "Sequence": null, "deprecation": null, "APICommander": null, "CollectionAPIOptions": null, "coerce_embedding_headers_provider": null, "CallerType": null, "DocumentType": "astrapy.constants.DocumentType", "FilterType": null, "ProjectionType": null, "ReturnDocument": null, "SortType": null, "VectorType": null, "normalize_optional_projection": null, "AsyncCursor": null, "Cursor": null, "AsyncDatabase": null, "Database": null, "DEFAULT_BULK_WRITE_CONCURRENCY": null, "DEFAULT_DATA_API_AUTH_HEADER": null, "DEFAULT_INSERT_MANY_CHUNK_SIZE": null, "DEFAULT_INSERT_MANY_CONCURRENCY": null, "NAMESPACE_DEPRECATION_NOTICE_METHOD": null, "SET_CALLER_DEPRECATION_NOTICE": null, "BulkWriteException": null, "CollectionNotFoundException": null, "CumulativeOperationException": null, "DataAPIFaultyResponseException": null, "DataAPIResponseException": null, "DeleteManyException": null, "InsertManyException": null, "MultiCallTimeoutManager": null, "TooManyDocumentsToCountException": null, "UpdateManyException": null, "base_timeout_info": null, "CollectionInfo": null, "CollectionOptions": null, "check_caller_parameters": null, "check_deprecated_vector_ize": null, "check_namespace_keyspace": null, "BulkWriteResult": null, "DeleteResult": null, "InsertManyResult": null, "InsertOneResult": null, "UpdateResult": null, "EmbeddingHeadersProvider": null, "AsyncBaseOperation": null, "BaseOperation": null, "dataclass": null, "TimeoutInfo": null, "OperationResult": null, "DEFAULT_REDACTED_HEADER_NAMES": null, "DEFAULT_REQUEST_TIMEOUT_MS": null, "HEADER_REDACT_PLACEHOLDER": null, "DataAPIHttpException": null, "DevOpsAPIFaultyResponseException": null, "DevOpsAPIHttpException": null, "DevOpsAPIResponseException": null, "to_dataapi_timeout_exception": null, "to_devopsapi_timeout_exception": null, "HttpMethod": null, "log_httpx_request": null, "log_httpx_response": null, "normalize_for_api": null, "restore_from_api": null, "compose_full_user_agent": null, "detect_astrapy_user_agent": null, "DeprecatedWarning": null, "CALLER_NAME_VERSION_DEPRECATION_NOTICE_DETAILS": null, "NAMESPACE_DEPRECATION_NOTICE_NS_DETAILS": null, "NAMESPACE_DEPRECATION_NOTICE_NS_SUBJECT": null, "NAMESPACE_DEPRECATION_NOTICE_UPDATEDBNS_DETAILS": null, "NAMESPACE_DEPRECATION_NOTICE_UPDATEDBNS_SUBJECT": null, "inspect": null, "queue": null, "threading": null, "weakref": null, "AsyncGenerator": null, "AsyncIterator": null, "partial": null, "Callable": null, "Iterator": null, "API_DOC": null, "AsyncPaginableRequestMethod": null, "PaginableRequestMethod": null, "DEFAULT_AUTH_HEADER": null, "DEFAULT_INSERT_NUM_DOCUMENTS": null, "DEFAULT_JSON_API_PATH": null, "DEFAULT_JSON_API_VERSION": null, "DEFAULT_KEYSPACE_NAME": null, "convert_vector_to_floats": null, "make_payload": null, "importlib": null, "os": null, "toml": null, "astrapy": null, "AstraDBAdmin": null, "AstraDBDatabaseAdmin": null, "DataAPIDatabaseAdmin": null, "DataAPIClient": null, "AsyncCollection": null, "Collection": null, "field": null, "TypeVar": null, "EmbeddingAPIKeyHeaderProvider": null, "ABC": null, "abstractmethod": null, "fetch_database_info": null, "parse_api_endpoint": null, "coerce_token_provider": null, "redact_secret": null, "Environment": null, "AsyncCommandCursor": null, "CommandCursor": null, "API_PATH_ENV_MAP": null, "API_VERSION_ENV_MAP": null, "DEFAULT_ASTRA_DB_KEYSPACE": null, "CollectionAlreadyExistsException": null, "DevOpsAPIException": null, "CollectionDescriptor": null, "CollectionVectorServiceOptions": null, "DatabaseInfo": null, "DatabaseAdmin": null, "TokenProvider": null, "api_endpoint_parsing_error_message": null, "build_api_endpoint": null, "check_id_endpoint_parg_kwargs": null, "generic_api_url_parsing_error_message": null, "normalize_region_for_id": null, "parse_generic_api_url": null, "check_deprecated_id_region": null, "hashlib": null, "Enum": null, "Generic": null, "Optional": null, "Tuple": null, "CursorIsStartedException": null, "DataAPITimeoutException": null, "normalize_payload_value": null, "DATA_API_ENVIRONMENT_CASSANDRA": null, "DATA_API_ENVIRONMENT_DEV": null, "DATA_API_ENVIRONMENT_DSE": null, "DATA_API_ENVIRONMENT_HCD": null, "DATA_API_ENVIRONMENT_OTHER": null, "DATA_API_ENVIRONMENT_PROD": null, "DATA_API_ENVIRONMENT_TEST": null, "reduce": null, "re": null, "API_ENDPOINT_TEMPLATE_ENV_MAP": null, "DEFAULT_DEV_OPS_AUTH_PREFIX": null, "DEV_OPS_DATABASE_POLL_INTERVAL_S": null, "DEV_OPS_DATABASE_STATUS_ACTIVE": null, "DEV_OPS_DATABASE_STATUS_INITIALIZING": null, "DEV_OPS_DATABASE_STATUS_MAINTENANCE": null, "DEV_OPS_DATABASE_STATUS_PENDING": null, "DEV_OPS_DATABASE_STATUS_TERMINATING": null, "DEV_OPS_DEFAULT_DATABASES_PAGE_SIZE": null, "DEV_OPS_KEYSPACE_POLL_INTERVAL_S": null, "DEV_OPS_RESPONSE_HTTP_ACCEPTED": null, "DEV_OPS_RESPONSE_HTTP_CREATED": null, "DEV_OPS_URL_ENV_MAP": null, "DEV_OPS_VERSION_ENV_MAP": null, "AdminDatabaseInfo": null, "FindEmbeddingProvidersResult": null, "check_update_db_namespace_keyspace": null, "base64": null, "EMBEDDING_HEADER_API_KEY": null, "EMBEDDING_HEADER_AWS_ACCESS_ID": null, "EMBEDDING_HEADER_AWS_SECRET_ID": null, "SECRETS_REDACT_CHAR": null, "SECRETS_REDACT_ENDING": null, "SECRETS_REDACT_ENDING_LENGTH": null }, "properties": { "is_init_module": false, "is_package": false, "is_subpackage": false, "is_namespace_package": false, "is_namespace_subpackage": false }, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.convert_vector_to_floats
Convert a vector of strings to a vector of floats.
{ "kind": "function", "name": "convert_vector_to_floats", "path": "astrapy.transform_payload.convert_vector_to_floats", "parameters": [ { "name": "vector", "type": "list", "description": "A vector of objects.", "default": null, "value": null } ], "returns": [ { "name": "list", "type": "list[float]", "description": "A vector of floats." } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.is_list_of_floats
Safely determine if it's a list of floats. Assumption: if list, and first item is float, then all items are.
{ "kind": "function", "name": "is_list_of_floats", "path": "astrapy.transform_payload.is_list_of_floats", "parameters": [ { "name": "vector", "type": "Iterable[Any]", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "bool", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.convert_to_ejson_date_object
{ "kind": "function", "name": "convert_to_ejson_date_object", "path": "astrapy.transform_payload.convert_to_ejson_date_object", "parameters": [ { "name": "date_value", "type": "datetime.date | datetime.datetime", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "dict[str, int]", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.convert_to_ejson_uuid_object
{ "kind": "function", "name": "convert_to_ejson_uuid_object", "path": "astrapy.transform_payload.convert_to_ejson_uuid_object", "parameters": [ { "name": "uuid_value", "type": "UUID", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "dict[str, str]", "description": null } ], "gathered_types": [ "UUID" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.convert_to_ejson_objectid_object
{ "kind": "function", "name": "convert_to_ejson_objectid_object", "path": "astrapy.transform_payload.convert_to_ejson_objectid_object", "parameters": [ { "name": "objectid_value", "type": "ObjectId", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "dict[str, str]", "description": null } ], "gathered_types": [ "ObjectId" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.convert_ejson_date_object_to_datetime
{ "kind": "function", "name": "convert_ejson_date_object_to_datetime", "path": "astrapy.transform_payload.convert_ejson_date_object_to_datetime", "parameters": [ { "name": "date_object", "type": "dict[str, int]", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "datetime.datetime", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.convert_ejson_uuid_object_to_uuid
{ "kind": "function", "name": "convert_ejson_uuid_object_to_uuid", "path": "astrapy.transform_payload.convert_ejson_uuid_object_to_uuid", "parameters": [ { "name": "uuid_object", "type": "dict[str, str]", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "UUID", "description": null } ], "gathered_types": [ "UUID" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.convert_ejson_objectid_object_to_objectid
{ "kind": "function", "name": "convert_ejson_objectid_object_to_objectid", "path": "astrapy.transform_payload.convert_ejson_objectid_object_to_objectid", "parameters": [ { "name": "objectid_object", "type": "dict[str, str]", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "ObjectId", "description": null } ], "gathered_types": [ "ObjectId" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.normalize_payload_value
The path helps determining special treatments
{ "kind": "function", "name": "normalize_payload_value", "path": "astrapy.transform_payload.normalize_payload_value", "parameters": [ { "name": "path", "type": "list[str]", "description": null, "default": null, "value": null }, { "name": "value", "type": "Any", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "Any", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.normalize_for_api
Normalize a payload for API calls. This includes e.g. ensuring values for "$vector" key are made into plain lists of floats.
{ "kind": "function", "name": "normalize_for_api", "path": "astrapy.transform_payload.normalize_for_api", "parameters": [ { "name": "payload", "type": "Dict[str, Any]", "description": "A dict expressing a payload for an API call", "default": null, "value": null } ], "returns": [ { "name": null, "type": "dict[str, Any] | None", "description": "Dict[str, Any]: a \"normalized\" payload dict" } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.restore_response_value
The path helps determining special treatments
{ "kind": "function", "name": "restore_response_value", "path": "astrapy.transform_payload.restore_response_value", "parameters": [ { "name": "path", "type": "list[str]", "description": null, "default": null, "value": null }, { "name": "value", "type": "Any", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "Any", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.transform_payload.restore_from_api
Process a dictionary just returned from the API. This is the place where e.g. `{"$date": 123}` is converted back into a datetime object.
{ "kind": "function", "name": "restore_from_api", "path": "astrapy.transform_payload.restore_from_api", "parameters": [ { "name": "response", "type": "DocumentType", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "DocumentType", "description": null } ], "gathered_types": [ "astrapy.constants.DocumentType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication
{ "kind": "module", "name": "authentication", "path": "astrapy.authentication", "parameters": null, "returns": null, "gathered_types": null, "value": null, "yields": null, "imports": { "annotations": "__future__.annotations", "logging": null, "Any": "typing.Any", "cast": null, "httpx": null, "API_RESPONSE": null, "amake_request": null, "make_request": null, "TypedDict": null, "APIRequestError": null, "api_request": null, "async_api_request": null, "async_raw_api_request": null, "raw_api_request": null, "OPS_API_RESPONSE": null, "DEFAULT_DEV_OPS_API_VERSION": null, "DEFAULT_DEV_OPS_AUTH_HEADER": null, "DEFAULT_DEV_OPS_URL": null, "TimeoutInfoWideType": null, "http_methods": null, "to_httpx_timeout": null, "Dict": null, "List": null, "Protocol": null, "Union": null, "datetime": null, "json": null, "time": null, "Iterable": null, "__version__": null, "DEFAULT_REDACTED_HEADERS": null, "DEFAULT_TIMEOUT": null, "UUID": null, "ObjectId": null, "uuid1": null, "uuid3": null, "uuid4": null, "uuid5": null, "uuid6": null, "uuid7": null, "uuid8": null, "AstraDB": null, "AstraDBCollection": null, "AsyncAstraDB": null, "AsyncAstraDBCollection": null, "logger": null, "AstraDBOps": null, "asyncio": null, "warnings": null, "ThreadPoolExecutor": null, "TracebackType": null, "TYPE_CHECKING": null, "Sequence": null, "deprecation": null, "APICommander": null, "CollectionAPIOptions": null, "coerce_embedding_headers_provider": null, "CallerType": null, "DocumentType": null, "FilterType": null, "ProjectionType": null, "ReturnDocument": null, "SortType": null, "VectorType": null, "normalize_optional_projection": null, "AsyncCursor": null, "Cursor": null, "AsyncDatabase": null, "Database": null, "DEFAULT_BULK_WRITE_CONCURRENCY": null, "DEFAULT_DATA_API_AUTH_HEADER": null, "DEFAULT_INSERT_MANY_CHUNK_SIZE": null, "DEFAULT_INSERT_MANY_CONCURRENCY": null, "NAMESPACE_DEPRECATION_NOTICE_METHOD": null, "SET_CALLER_DEPRECATION_NOTICE": null, "BulkWriteException": null, "CollectionNotFoundException": null, "CumulativeOperationException": null, "DataAPIFaultyResponseException": null, "DataAPIResponseException": null, "DeleteManyException": null, "InsertManyException": null, "MultiCallTimeoutManager": null, "TooManyDocumentsToCountException": null, "UpdateManyException": null, "base_timeout_info": null, "CollectionInfo": null, "CollectionOptions": null, "check_caller_parameters": null, "check_deprecated_vector_ize": null, "check_namespace_keyspace": null, "BulkWriteResult": null, "DeleteResult": null, "InsertManyResult": null, "InsertOneResult": null, "UpdateResult": null, "EmbeddingHeadersProvider": null, "AsyncBaseOperation": null, "BaseOperation": null, "dataclass": null, "TimeoutInfo": null, "OperationResult": null, "DEFAULT_REDACTED_HEADER_NAMES": null, "DEFAULT_REQUEST_TIMEOUT_MS": null, "HEADER_REDACT_PLACEHOLDER": null, "DataAPIHttpException": null, "DevOpsAPIFaultyResponseException": null, "DevOpsAPIHttpException": null, "DevOpsAPIResponseException": null, "to_dataapi_timeout_exception": null, "to_devopsapi_timeout_exception": null, "HttpMethod": null, "log_httpx_request": null, "log_httpx_response": null, "normalize_for_api": null, "restore_from_api": null, "compose_full_user_agent": null, "detect_astrapy_user_agent": null, "DeprecatedWarning": null, "CALLER_NAME_VERSION_DEPRECATION_NOTICE_DETAILS": null, "NAMESPACE_DEPRECATION_NOTICE_NS_DETAILS": null, "NAMESPACE_DEPRECATION_NOTICE_NS_SUBJECT": null, "NAMESPACE_DEPRECATION_NOTICE_UPDATEDBNS_DETAILS": null, "NAMESPACE_DEPRECATION_NOTICE_UPDATEDBNS_SUBJECT": null, "inspect": null, "queue": null, "threading": null, "weakref": null, "AsyncGenerator": null, "AsyncIterator": null, "partial": null, "Callable": null, "Iterator": null, "API_DOC": null, "AsyncPaginableRequestMethod": null, "PaginableRequestMethod": null, "DEFAULT_AUTH_HEADER": null, "DEFAULT_INSERT_NUM_DOCUMENTS": null, "DEFAULT_JSON_API_PATH": null, "DEFAULT_JSON_API_VERSION": null, "DEFAULT_KEYSPACE_NAME": null, "convert_vector_to_floats": null, "make_payload": null, "importlib": null, "os": null, "toml": null, "astrapy": null, "AstraDBAdmin": null, "AstraDBDatabaseAdmin": null, "DataAPIDatabaseAdmin": null, "DataAPIClient": null, "AsyncCollection": null, "Collection": null, "field": null, "TypeVar": null, "EmbeddingAPIKeyHeaderProvider": null, "ABC": "abc.ABC", "abstractmethod": "abc.abstractmethod", "fetch_database_info": null, "parse_api_endpoint": null, "coerce_token_provider": null, "redact_secret": null, "Environment": null, "AsyncCommandCursor": null, "CommandCursor": null, "API_PATH_ENV_MAP": null, "API_VERSION_ENV_MAP": null, "DEFAULT_ASTRA_DB_KEYSPACE": null, "CollectionAlreadyExistsException": null, "DevOpsAPIException": null, "CollectionDescriptor": null, "CollectionVectorServiceOptions": null, "DatabaseInfo": null, "DatabaseAdmin": null, "TokenProvider": null, "api_endpoint_parsing_error_message": null, "build_api_endpoint": null, "check_id_endpoint_parg_kwargs": null, "generic_api_url_parsing_error_message": null, "normalize_region_for_id": null, "parse_generic_api_url": null, "check_deprecated_id_region": null, "hashlib": null, "Enum": null, "Generic": null, "Optional": null, "Tuple": null, "CursorIsStartedException": null, "DataAPITimeoutException": null, "normalize_payload_value": null, "DATA_API_ENVIRONMENT_CASSANDRA": null, "DATA_API_ENVIRONMENT_DEV": null, "DATA_API_ENVIRONMENT_DSE": null, "DATA_API_ENVIRONMENT_HCD": null, "DATA_API_ENVIRONMENT_OTHER": null, "DATA_API_ENVIRONMENT_PROD": null, "DATA_API_ENVIRONMENT_TEST": null, "reduce": null, "re": null, "API_ENDPOINT_TEMPLATE_ENV_MAP": null, "DEFAULT_DEV_OPS_AUTH_PREFIX": null, "DEV_OPS_DATABASE_POLL_INTERVAL_S": null, "DEV_OPS_DATABASE_STATUS_ACTIVE": null, "DEV_OPS_DATABASE_STATUS_INITIALIZING": null, "DEV_OPS_DATABASE_STATUS_MAINTENANCE": null, "DEV_OPS_DATABASE_STATUS_PENDING": null, "DEV_OPS_DATABASE_STATUS_TERMINATING": null, "DEV_OPS_DEFAULT_DATABASES_PAGE_SIZE": null, "DEV_OPS_KEYSPACE_POLL_INTERVAL_S": null, "DEV_OPS_RESPONSE_HTTP_ACCEPTED": null, "DEV_OPS_RESPONSE_HTTP_CREATED": null, "DEV_OPS_URL_ENV_MAP": null, "DEV_OPS_VERSION_ENV_MAP": null, "AdminDatabaseInfo": null, "FindEmbeddingProvidersResult": null, "check_update_db_namespace_keyspace": null, "base64": "base64", "EMBEDDING_HEADER_API_KEY": "astrapy.defaults.EMBEDDING_HEADER_API_KEY", "EMBEDDING_HEADER_AWS_ACCESS_ID": "astrapy.defaults.EMBEDDING_HEADER_AWS_ACCESS_ID", "EMBEDDING_HEADER_AWS_SECRET_ID": "astrapy.defaults.EMBEDDING_HEADER_AWS_SECRET_ID", "SECRETS_REDACT_CHAR": "astrapy.defaults.SECRETS_REDACT_CHAR", "SECRETS_REDACT_ENDING": "astrapy.defaults.SECRETS_REDACT_ENDING", "SECRETS_REDACT_ENDING_LENGTH": "astrapy.defaults.SECRETS_REDACT_ENDING_LENGTH" }, "properties": { "is_init_module": false, "is_package": false, "is_subpackage": false, "is_namespace_package": false, "is_namespace_subpackage": false }, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.coerce_token_provider
{ "kind": "function", "name": "coerce_token_provider", "path": "astrapy.authentication.coerce_token_provider", "parameters": [ { "name": "token", "type": "str | TokenProvider | None", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "TokenProvider", "description": null } ], "gathered_types": [ "astrapy.authentication.TokenProvider" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.coerce_embedding_headers_provider
{ "kind": "function", "name": "coerce_embedding_headers_provider", "path": "astrapy.authentication.coerce_embedding_headers_provider", "parameters": [ { "name": "embedding_api_key", "type": "str | EmbeddingHeadersProvider | None", "description": null, "default": null, "value": null } ], "returns": [ { "name": null, "type": "EmbeddingHeadersProvider", "description": null } ], "gathered_types": [ "astrapy.authentication.EmbeddingHeadersProvider" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.redact_secret
Return a shortened-if-necessary version of a 'secret' string (with ellipsis).
{ "kind": "function", "name": "redact_secret", "path": "astrapy.authentication.redact_secret", "parameters": [ { "name": "secret", "type": "str", "description": "a secret string to redact", "default": null, "value": null }, { "name": "max_length", "type": "int", "description": "if the secret and the fixed ending exceed this size,\nshortening takes place.", "default": null, "value": null }, { "name": "hide_if_short", "type": "bool", "description": "this controls what to do when the input secret is\nshorter, i.e. when no shortening takes place.\nif False, the secret is returned as-is;\nIf True, a masked string is returned of the same length as secret.", "default": "True", "value": "True" } ], "returns": [ { "name": null, "type": "str", "description": "a 'redacted' form of the secret string as per the rules outlined above." } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.TokenProvider
Abstract base class for a token provider. The relevant method in this interface is returning a string to use as token. The __str__ / __repr__ methods are NOT to be used as source of tokens: use get_token instead. Note that equality (__eq__) checks if the generated tokens match under all circumstances (e.g. a literal passthrough matches a different-encoding token provider that yields the same token). If a token provider comes that encodes a recipe for nondeterministic periodic renewal, its __eq__ method will have to override the one in this class.
{ "kind": "class", "name": "TokenProvider", "path": "astrapy.authentication.TokenProvider", "parameters": null, "returns": null, "gathered_types": [ "ABC" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": [ "ABC" ], "exports": null, "example": null, "references": null, "note": null, "implemented_by": [ "astrapy.authentication.UsernamePasswordTokenProvider", "astrapy.authentication.StaticTokenProvider" ], "attributes": null }
astrapy.authentication.TokenProvider.get_token
Produce a string for direct use as token in a subsequent API request, or None for no token.
{ "kind": "function", "name": "get_token", "path": "astrapy.authentication.TokenProvider.get_token", "parameters": null, "returns": [ { "name": null, "type": "str | None", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.StaticTokenProvider
A "pass-through" provider that wraps a supplied literal token.
{ "kind": "class", "name": "StaticTokenProvider", "path": "astrapy.authentication.StaticTokenProvider", "parameters": [ { "name": "token", "type": "str | None", "description": "an access token for subsequent use in the client.", "default": null, "value": null } ], "returns": null, "gathered_types": [ "astrapy.authentication.TokenProvider" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": [ "astrapy.authentication.TokenProvider" ], "exports": null, "example": ">>> from astrapy import DataAPIClient\n>>> from astrapy.authentication import StaticTokenProvider\n>>> token_provider = StaticTokenProvider(\"AstraCS:xyz...\")\n>>> database = DataAPIClient().get_database(\n... \"https://01234567-...-eu-west1.apps.datastax.com\",\n... token=token_provider,\n... )", "references": [ "astrapy.client.DataAPIClient" ], "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.StaticTokenProvider.token
{ "kind": "attribute", "name": "token", "path": "astrapy.authentication.StaticTokenProvider.token", "parameters": null, "returns": null, "gathered_types": null, "value": "token = token", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.StaticTokenProvider.get_token
{ "kind": "function", "name": "get_token", "path": "astrapy.authentication.StaticTokenProvider.get_token", "parameters": null, "returns": [ { "name": null, "type": "str | None", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.UsernamePasswordTokenProvider
A token provider encoding username/password-based authentication, as used e.g. for DSE and HCD. These are base64-encoded and concatenated by colons, with a prepended suffix 'Cassandra', as required by this authentication scheme.
{ "kind": "class", "name": "UsernamePasswordTokenProvider", "path": "astrapy.authentication.UsernamePasswordTokenProvider", "parameters": [ { "name": "username", "type": "str", "description": "the username for accessing the database.", "default": null, "value": null }, { "name": "password", "type": "str", "description": "the corresponding password.", "default": null, "value": null } ], "returns": null, "gathered_types": [ "astrapy.authentication.TokenProvider" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": [ "astrapy.authentication.TokenProvider" ], "exports": null, "example": ">>> from astrapy import DataAPIClient\n>>> from astrapy.constants imort Environment\n>>> from astrapy.authentication import UsernamePasswordTokenProvider\n>>> token_provider = UsernamePasswordTokenProvider(\"username\", \"password\")\n>>> database = DataAPIClient(environment=Environment.HCD).get_database(\n... \"http://localhost:8181\",\n... token=token_provider,\n... )", "references": [ "astrapy.constants.Environment", "astrapy.client.DataAPIClient" ], "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.UsernamePasswordTokenProvider.PREFIX
{ "kind": "attribute", "name": "PREFIX", "path": "astrapy.authentication.UsernamePasswordTokenProvider.PREFIX", "parameters": null, "returns": null, "gathered_types": null, "value": "PREFIX = 'Cassandra'", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.UsernamePasswordTokenProvider.username
{ "kind": "attribute", "name": "username", "path": "astrapy.authentication.UsernamePasswordTokenProvider.username", "parameters": null, "returns": null, "gathered_types": null, "value": "username = username", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.UsernamePasswordTokenProvider.password
{ "kind": "attribute", "name": "password", "path": "astrapy.authentication.UsernamePasswordTokenProvider.password", "parameters": null, "returns": null, "gathered_types": null, "value": "password = password", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.UsernamePasswordTokenProvider.token
{ "kind": "attribute", "name": "token", "path": "astrapy.authentication.UsernamePasswordTokenProvider.token", "parameters": null, "returns": null, "gathered_types": [ "_b64", "PREFIX" ], "value": "token = f'{self.PREFIX}:{self._b64(self.username)}:{self._b64(self.password)}'", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.UsernamePasswordTokenProvider.get_token
{ "kind": "function", "name": "get_token", "path": "astrapy.authentication.UsernamePasswordTokenProvider.get_token", "parameters": null, "returns": [ { "name": null, "type": "str", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.EmbeddingHeadersProvider
Abstract base class for a provider of embedding-related headers (such as API Keys). The relevant method in this interface is returning a dict to use as (part of the) headers in Data API requests for a collection. This class captures the fact that, depending on the embedding provider for the collection, there may be zero, one *or more* headers to be passed if relying on the HEADERS auth method for Vectorize.
{ "kind": "class", "name": "EmbeddingHeadersProvider", "path": "astrapy.authentication.EmbeddingHeadersProvider", "parameters": null, "returns": null, "gathered_types": [ "ABC" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": [ "ABC" ], "exports": null, "example": null, "references": null, "note": null, "implemented_by": [ "astrapy.authentication.EmbeddingAPIKeyHeaderProvider", "astrapy.authentication.AWSEmbeddingHeadersProvider" ], "attributes": null }
astrapy.authentication.EmbeddingHeadersProvider.get_headers
Produce a dictionary for use as (part of) the headers in HTTP requests to the Data API.
{ "kind": "function", "name": "get_headers", "path": "astrapy.authentication.EmbeddingHeadersProvider.get_headers", "parameters": null, "returns": [ { "name": null, "type": "dict[str, str]", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.EmbeddingAPIKeyHeaderProvider
A "pass-through" header provider representing the single-header (typically "X-Embedding-Api-Key") auth scheme, in use by most of the embedding models in Vectorize.
{ "kind": "class", "name": "EmbeddingAPIKeyHeaderProvider", "path": "astrapy.authentication.EmbeddingAPIKeyHeaderProvider", "parameters": [ { "name": "embedding_api_key", "type": "str | None", "description": "a string that will be the value for the header.\nIf None is passed, this results in a no-headers provider (such\nas the one used for non-Vectorize collections).", "default": null, "value": null } ], "returns": null, "gathered_types": [ "astrapy.authentication.EmbeddingHeadersProvider" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": [ "astrapy.authentication.EmbeddingHeadersProvider" ], "exports": null, "example": ">>> from astrapy import DataAPIClient\n>>> from astrapy.authentication import (\n CollectionVectorServiceOptions,\n EmbeddingAPIKeyHeaderProvider,\n)\n>>> my_emb_api_key = EmbeddingAPIKeyHeaderProvider(\"abc012...\")\n>>> service_options = CollectionVectorServiceOptions(\n... provider=\"a-certain-provider\",\n... model_name=\"some-embedding-model\",\n... )\n>>>\n>>> database = DataAPIClient().get_database(\n... \"https://01234567-...-eu-west1.apps.datastax.com\",\n... token=\"AstraCS:...\",\n... )\n>>> collection = database.create_collection(\n... \"vectorize_collection\",\n... service=service_options,\n... embedding_api_key=my_emb_api_key,\n... )\n>>> # likewise:\n>>> collection_b = database.get_collection(\n... \"vectorize_collection\",\n... embedding_api_key=my_emb_api_key,\n... )", "references": [ "astrapy.authentication.CollectionVectorServiceOptions", "astrapy.client.DataAPIClient" ], "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.EmbeddingAPIKeyHeaderProvider.embedding_api_key
{ "kind": "attribute", "name": "embedding_api_key", "path": "astrapy.authentication.EmbeddingAPIKeyHeaderProvider.embedding_api_key", "parameters": null, "returns": null, "gathered_types": null, "value": "embedding_api_key = embedding_api_key", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.EmbeddingAPIKeyHeaderProvider.get_headers
{ "kind": "function", "name": "get_headers", "path": "astrapy.authentication.EmbeddingAPIKeyHeaderProvider.get_headers", "parameters": null, "returns": [ { "name": null, "type": "dict[str, str]", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.AWSEmbeddingHeadersProvider
A header provider representing the two-header auth scheme in use by the Amazon Web Services (e.g. AWS Bedrock) when using header-based authentication.
{ "kind": "class", "name": "AWSEmbeddingHeadersProvider", "path": "astrapy.authentication.AWSEmbeddingHeadersProvider", "parameters": [ { "name": "embedding_access_id", "type": "str", "description": "value of the \"Access ID\" secret. This will become\nthe value for the corresponding header.", "default": null, "value": null }, { "name": "embedding_secret_id", "type": "str", "description": "value of the \"Secret ID\" secret. This will become\nthe value for the corresponding header.", "default": null, "value": null } ], "returns": null, "gathered_types": [ "astrapy.authentication.EmbeddingHeadersProvider" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": [ "astrapy.authentication.EmbeddingHeadersProvider" ], "exports": null, "example": ">>> from astrapy import DataAPIClient\n>>> from astrapy.authentication import (\n CollectionVectorServiceOptions,\n AWSEmbeddingHeadersProvider,\n)\n>>> my_aws_emb_api_key = AWSEmbeddingHeadersProvider(\n embedding_access_id=\"my-access-id-012...\",\n embedding_secret_id=\"my-secret-id-abc...\",\n)\n>>> service_options = CollectionVectorServiceOptions(\n... provider=\"bedrock\",\n... model_name=\"some-aws-bedrock-model\",\n... )\n>>>\n>>> database = DataAPIClient().get_database(\n... \"https://01234567-...-eu-west1.apps.datastax.com\",\n... token=\"AstraCS:...\",\n... )\n>>> collection = database.create_collection(\n... \"vectorize_aws_collection\",\n... service=service_options,\n... embedding_api_key=my_aws_emb_api_key,\n... )\n>>> # likewise:\n>>> collection_b = database.get_collection(\n... \"vectorize_aws_collection\",\n... embedding_api_key=my_aws_emb_api_key,\n... )", "references": [ "astrapy.authentication.CollectionVectorServiceOptions", "astrapy.client.DataAPIClient" ], "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.AWSEmbeddingHeadersProvider.embedding_access_id
{ "kind": "attribute", "name": "embedding_access_id", "path": "astrapy.authentication.AWSEmbeddingHeadersProvider.embedding_access_id", "parameters": null, "returns": null, "gathered_types": null, "value": "embedding_access_id = embedding_access_id", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.AWSEmbeddingHeadersProvider.embedding_secret_id
{ "kind": "attribute", "name": "embedding_secret_id", "path": "astrapy.authentication.AWSEmbeddingHeadersProvider.embedding_secret_id", "parameters": null, "returns": null, "gathered_types": null, "value": "embedding_secret_id = embedding_secret_id", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.authentication.AWSEmbeddingHeadersProvider.get_headers
{ "kind": "function", "name": "get_headers", "path": "astrapy.authentication.AWSEmbeddingHeadersProvider.get_headers", "parameters": null, "returns": [ { "name": null, "type": "dict[str, str]", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection
{ "kind": "module", "name": "collection", "path": "astrapy.collection", "parameters": null, "returns": null, "gathered_types": null, "value": null, "yields": null, "imports": { "annotations": "__future__.annotations", "logging": "logging", "Any": "typing.Any", "cast": null, "httpx": null, "API_RESPONSE": null, "amake_request": null, "make_request": null, "TypedDict": null, "APIRequestError": null, "api_request": null, "async_api_request": null, "async_raw_api_request": null, "raw_api_request": null, "OPS_API_RESPONSE": null, "DEFAULT_DEV_OPS_API_VERSION": null, "DEFAULT_DEV_OPS_AUTH_HEADER": null, "DEFAULT_DEV_OPS_URL": null, "TimeoutInfoWideType": null, "http_methods": null, "to_httpx_timeout": null, "Dict": null, "List": null, "Protocol": null, "Union": null, "datetime": null, "json": "json", "time": null, "Iterable": "typing.Iterable", "__version__": "astrapy.__version__", "DEFAULT_REDACTED_HEADERS": null, "DEFAULT_TIMEOUT": null, "UUID": null, "ObjectId": null, "uuid1": null, "uuid3": null, "uuid4": null, "uuid5": null, "uuid6": null, "uuid7": null, "uuid8": null, "AstraDB": null, "AstraDBCollection": null, "AsyncAstraDB": null, "AsyncAstraDBCollection": null, "logger": null, "AstraDBOps": null, "asyncio": "asyncio", "warnings": "warnings", "ThreadPoolExecutor": "concurrent.futures.ThreadPoolExecutor", "TracebackType": "types.TracebackType", "TYPE_CHECKING": "typing.TYPE_CHECKING", "Sequence": "typing.Sequence", "deprecation": "deprecation", "APICommander": "astrapy.api_commander.APICommander", "CollectionAPIOptions": "astrapy.api_options.CollectionAPIOptions", "coerce_embedding_headers_provider": "astrapy.authentication.coerce_embedding_headers_provider", "CallerType": "astrapy.constants.CallerType", "DocumentType": "astrapy.constants.DocumentType", "FilterType": "astrapy.constants.FilterType", "ProjectionType": "astrapy.constants.ProjectionType", "ReturnDocument": "astrapy.constants.ReturnDocument", "SortType": "astrapy.constants.SortType", "VectorType": "astrapy.constants.VectorType", "normalize_optional_projection": "astrapy.constants.normalize_optional_projection", "AsyncCursor": "astrapy.cursors.AsyncCursor", "Cursor": "astrapy.cursors.Cursor", "AsyncDatabase": "astrapy.database.AsyncDatabase", "Database": "astrapy.database.Database", "DEFAULT_BULK_WRITE_CONCURRENCY": "astrapy.defaults.DEFAULT_BULK_WRITE_CONCURRENCY", "DEFAULT_DATA_API_AUTH_HEADER": "astrapy.defaults.DEFAULT_DATA_API_AUTH_HEADER", "DEFAULT_INSERT_MANY_CHUNK_SIZE": "astrapy.defaults.DEFAULT_INSERT_MANY_CHUNK_SIZE", "DEFAULT_INSERT_MANY_CONCURRENCY": "astrapy.defaults.DEFAULT_INSERT_MANY_CONCURRENCY", "NAMESPACE_DEPRECATION_NOTICE_METHOD": "astrapy.defaults.NAMESPACE_DEPRECATION_NOTICE_METHOD", "SET_CALLER_DEPRECATION_NOTICE": "astrapy.defaults.SET_CALLER_DEPRECATION_NOTICE", "BulkWriteException": "astrapy.exceptions.BulkWriteException", "CollectionNotFoundException": "astrapy.exceptions.CollectionNotFoundException", "CumulativeOperationException": "astrapy.exceptions.CumulativeOperationException", "DataAPIFaultyResponseException": "astrapy.exceptions.DataAPIFaultyResponseException", "DataAPIResponseException": "astrapy.exceptions.DataAPIResponseException", "DeleteManyException": "astrapy.exceptions.DeleteManyException", "InsertManyException": "astrapy.exceptions.InsertManyException", "MultiCallTimeoutManager": "astrapy.exceptions.MultiCallTimeoutManager", "TooManyDocumentsToCountException": "astrapy.exceptions.TooManyDocumentsToCountException", "UpdateManyException": "astrapy.exceptions.UpdateManyException", "base_timeout_info": "astrapy.exceptions.base_timeout_info", "CollectionInfo": "astrapy.info.CollectionInfo", "CollectionOptions": "astrapy.info.CollectionOptions", "check_caller_parameters": "astrapy.meta.check_caller_parameters", "check_deprecated_vector_ize": "astrapy.meta.check_deprecated_vector_ize", "check_namespace_keyspace": "astrapy.meta.check_namespace_keyspace", "BulkWriteResult": "astrapy.results.BulkWriteResult", "DeleteResult": "astrapy.results.DeleteResult", "InsertManyResult": "astrapy.results.InsertManyResult", "InsertOneResult": "astrapy.results.InsertOneResult", "UpdateResult": "astrapy.results.UpdateResult", "EmbeddingHeadersProvider": "astrapy.authentication.EmbeddingHeadersProvider", "AsyncBaseOperation": "astrapy.operations.AsyncBaseOperation", "BaseOperation": "astrapy.operations.BaseOperation", "dataclass": null, "TimeoutInfo": null, "OperationResult": null, "DEFAULT_REDACTED_HEADER_NAMES": null, "DEFAULT_REQUEST_TIMEOUT_MS": null, "HEADER_REDACT_PLACEHOLDER": null, "DataAPIHttpException": null, "DevOpsAPIFaultyResponseException": null, "DevOpsAPIHttpException": null, "DevOpsAPIResponseException": null, "to_dataapi_timeout_exception": null, "to_devopsapi_timeout_exception": null, "HttpMethod": null, "log_httpx_request": null, "log_httpx_response": null, "normalize_for_api": null, "restore_from_api": null, "compose_full_user_agent": null, "detect_astrapy_user_agent": null, "DeprecatedWarning": null, "CALLER_NAME_VERSION_DEPRECATION_NOTICE_DETAILS": null, "NAMESPACE_DEPRECATION_NOTICE_NS_DETAILS": null, "NAMESPACE_DEPRECATION_NOTICE_NS_SUBJECT": null, "NAMESPACE_DEPRECATION_NOTICE_UPDATEDBNS_DETAILS": null, "NAMESPACE_DEPRECATION_NOTICE_UPDATEDBNS_SUBJECT": null, "inspect": null, "queue": null, "threading": null, "weakref": null, "AsyncGenerator": null, "AsyncIterator": null, "partial": null, "Callable": null, "Iterator": null, "API_DOC": null, "AsyncPaginableRequestMethod": null, "PaginableRequestMethod": null, "DEFAULT_AUTH_HEADER": null, "DEFAULT_INSERT_NUM_DOCUMENTS": null, "DEFAULT_JSON_API_PATH": null, "DEFAULT_JSON_API_VERSION": null, "DEFAULT_KEYSPACE_NAME": null, "convert_vector_to_floats": null, "make_payload": null, "importlib": null, "os": null, "toml": null, "astrapy": null, "AstraDBAdmin": null, "AstraDBDatabaseAdmin": null, "DataAPIDatabaseAdmin": null, "DataAPIClient": null, "AsyncCollection": null, "Collection": null, "field": null, "TypeVar": null, "EmbeddingAPIKeyHeaderProvider": null, "ABC": null, "abstractmethod": null, "fetch_database_info": null, "parse_api_endpoint": null, "coerce_token_provider": null, "redact_secret": null, "Environment": null, "AsyncCommandCursor": null, "CommandCursor": null, "API_PATH_ENV_MAP": null, "API_VERSION_ENV_MAP": null, "DEFAULT_ASTRA_DB_KEYSPACE": null, "CollectionAlreadyExistsException": null, "DevOpsAPIException": null, "CollectionDescriptor": null, "CollectionVectorServiceOptions": null, "DatabaseInfo": null, "DatabaseAdmin": null, "TokenProvider": null, "api_endpoint_parsing_error_message": null, "build_api_endpoint": null, "check_id_endpoint_parg_kwargs": null, "generic_api_url_parsing_error_message": null, "normalize_region_for_id": null, "parse_generic_api_url": null, "check_deprecated_id_region": null, "hashlib": null, "Enum": null, "Generic": null, "Optional": null, "Tuple": null, "CursorIsStartedException": null, "DataAPITimeoutException": null, "normalize_payload_value": null, "DATA_API_ENVIRONMENT_CASSANDRA": null, "DATA_API_ENVIRONMENT_DEV": null, "DATA_API_ENVIRONMENT_DSE": null, "DATA_API_ENVIRONMENT_HCD": null, "DATA_API_ENVIRONMENT_OTHER": null, "DATA_API_ENVIRONMENT_PROD": null, "DATA_API_ENVIRONMENT_TEST": null, "reduce": null, "re": null, "API_ENDPOINT_TEMPLATE_ENV_MAP": null, "DEFAULT_DEV_OPS_AUTH_PREFIX": null, "DEV_OPS_DATABASE_POLL_INTERVAL_S": null, "DEV_OPS_DATABASE_STATUS_ACTIVE": null, "DEV_OPS_DATABASE_STATUS_INITIALIZING": null, "DEV_OPS_DATABASE_STATUS_MAINTENANCE": null, "DEV_OPS_DATABASE_STATUS_PENDING": null, "DEV_OPS_DATABASE_STATUS_TERMINATING": null, "DEV_OPS_DEFAULT_DATABASES_PAGE_SIZE": null, "DEV_OPS_KEYSPACE_POLL_INTERVAL_S": null, "DEV_OPS_RESPONSE_HTTP_ACCEPTED": null, "DEV_OPS_RESPONSE_HTTP_CREATED": null, "DEV_OPS_URL_ENV_MAP": null, "DEV_OPS_VERSION_ENV_MAP": null, "AdminDatabaseInfo": null, "FindEmbeddingProvidersResult": null, "check_update_db_namespace_keyspace": null, "base64": null, "EMBEDDING_HEADER_API_KEY": null, "EMBEDDING_HEADER_AWS_ACCESS_ID": null, "EMBEDDING_HEADER_AWS_SECRET_ID": null, "SECRETS_REDACT_CHAR": null, "SECRETS_REDACT_ENDING": null, "SECRETS_REDACT_ENDING_LENGTH": null }, "properties": { "is_init_module": false, "is_package": false, "is_subpackage": false, "is_namespace_package": false, "is_namespace_subpackage": false }, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.logger
{ "kind": "attribute", "name": "logger", "path": "astrapy.collection.logger", "parameters": null, "returns": null, "gathered_types": [ "__name__" ], "value": "logger = logging.getLogger(__name__)", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection
A Data API collection, the main object to interact with the Data API, especially for DDL operations. This class has a synchronous interface. A Collection is spawned from a Database object, from which it inherits the details on how to reach the API server (endpoint, authentication token).
{ "kind": "class", "name": "Collection", "path": "astrapy.collection.Collection", "parameters": [ { "name": "database", "type": "Database", "description": "a Database object, instantiated earlier. This represents\nthe database the collection belongs to.", "default": null, "value": null }, { "name": "name", "type": "str", "description": "the collection name. This parameter should match an existing\ncollection on the database.", "default": null, "value": null }, { "name": "keyspace", "type": "str | None", "description": "this is the keyspace to which the collection belongs.\nIf not specified, the database's working keyspace is used.", "default": "None", "value": "None" }, { "name": "namespace", "type": "str | None", "description": "an alias for `keyspace`. *DEPRECATED*, removal in 2.0.", "default": "None", "value": "None" }, { "name": "api_options", "type": "CollectionAPIOptions | None", "description": "An instance of `astrapy.api_options.CollectionAPIOptions`\nproviding the general settings for interacting with the Data API.", "default": "None", "value": "None" }, { "name": "callers", "type": "Sequence[CallerType]", "description": "a list of caller identities, i.e. applications, or frameworks,\non behalf of which the Data API calls are performed. These end up\nin the request user-agent.\nEach caller identity is a (\"caller_name\", \"caller_version\") pair.", "default": "[]", "value": "[]" }, { "name": "caller_name", "type": "str | None", "description": "*DEPRECATED*, use `callers`. Removal 2.0. Name of the\napplication, or framework, on behalf of which the Data API calls\nare performed. This ends up in the request user-agent.", "default": "None", "value": "None" }, { "name": "caller_version", "type": "str | None", "description": "version of the caller. *DEPRECATED*, use `callers`. Removal 2.0.", "default": "None", "value": "None" } ], "returns": null, "gathered_types": [ "astrapy.constants.CallerType", "astrapy.database.Database", "astrapy.api_options.CollectionAPIOptions" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> from astrapy import DataAPIClient, Collection\n>>> my_client = astrapy.DataAPIClient(\"AstraCS:...\")\n>>> my_db = my_client.get_database(\n... \"https://01234567-....apps.astra.datastax.com\"\n... )\n>>> my_coll_1 = Collection(database=my_db, name=\"my_collection\")\n>>> my_coll_2 = my_db.create_collection(\n... \"my_v_collection\",\n... dimension=3,\n... metric=\"cosine\",\n... )\n>>> my_coll_3a = my_db.get_collection(\"my_already_existing_collection\")\n>>> my_coll_3b = my_db.my_already_existing_collection\n>>> my_coll_3c = my_db[\"my_already_existing_collection\"]", "references": [ "astrapy.collection.Collection", "astrapy.client.DataAPIClient" ], "note": "creating an instance of Collection does not trigger actual creation\nof the collection on the database. The latter should have been created\nbeforehand, e.g. through the `create_collection` method of a Database.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.api_options
{ "kind": "attribute", "name": "api_options", "path": "astrapy.collection.Collection.api_options", "parameters": null, "returns": null, "gathered_types": [ "astrapy.api_options.CollectionAPIOptions" ], "value": "api_options = CollectionAPIOptions()", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.callers
{ "kind": "attribute", "name": "callers", "path": "astrapy.collection.Collection.callers", "parameters": null, "returns": null, "gathered_types": null, "value": "callers = callers_param", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.with_options
Create a clone of this collection with some changed attributes.
{ "kind": "function", "name": "with_options", "path": "astrapy.collection.Collection.with_options", "parameters": [ { "name": "name", "type": "str | None", "description": "the name of the collection. This parameter is useful to\nquickly spawn Collection instances each pointing to a different\ncollection existing in the same keyspace.", "default": "None", "value": "None" }, { "name": "embedding_api_key", "type": "str | EmbeddingHeadersProvider | None", "description": "optional API key(s) for interacting with the collection.\nIf an embedding service is configured, and this parameter is not None,\neach Data API call will include the necessary embedding-related headers\nas specified by this parameter. If a string is passed, it translates\ninto the one \"embedding api key\" header\n(i.e. `astrapy.authentication.EmbeddingAPIKeyHeaderProvider`).\nFor some vectorize providers/models, if using header-based authentication,\nspecialized subclasses of `astrapy.authentication.EmbeddingHeadersProvider`\nshould be supplied.", "default": "None", "value": "None" }, { "name": "collection_max_time_ms", "type": "int | None", "description": "a default timeout, in millisecond, for the duration of each\noperation on the collection. Individual timeouts can be provided to\neach collection method call and will take precedence, with this value\nbeing an overall default.\nNote that for some methods involving multiple API calls (such as\n`find`, `delete_many`, `insert_many` and so on), it is strongly suggested\nto provide a specific timeout as the default one likely wouldn't make\nmuch sense.", "default": "None", "value": "None" }, { "name": "callers", "type": "Sequence[CallerType]", "description": "a list of caller identities, i.e. applications, or frameworks,\non behalf of which the Data API calls are performed. These end up\nin the request user-agent.\nEach caller identity is a (\"caller_name\", \"caller_version\") pair.", "default": "[]", "value": "[]" }, { "name": "caller_name", "type": "str | None", "description": "*DEPRECATED*, use `callers`. Removal 2.0. Name of the\napplication, or framework, on behalf of which the Data API calls\nare performed. This ends up in the request user-agent.", "default": "None", "value": "None" }, { "name": "caller_version", "type": "str | None", "description": "version of the caller. *DEPRECATED*, use `callers`.\nRemoval 2.0.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "Collection", "description": "a new Collection instance." } ], "gathered_types": [ "astrapy.authentication.EmbeddingHeadersProvider", "astrapy.constants.CallerType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_other_coll = my_coll.with_options(\n... name=\"the_other_coll\",\n... callers=[(\"caller_identity\", \"0.1.2\")],\n... )", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.to_async
Create an AsyncCollection from this one. Save for the arguments explicitly provided as overrides, everything else is kept identical to this collection in the copy (the database is converted into an async object).
{ "kind": "function", "name": "to_async", "path": "astrapy.collection.Collection.to_async", "parameters": [ { "name": "database", "type": "AsyncDatabase | None", "description": "an AsyncDatabase object, instantiated earlier.\nThis represents the database the new collection belongs to.", "default": "None", "value": "None" }, { "name": "name", "type": "str | None", "description": "the collection name. This parameter should match an existing\ncollection on the database.", "default": "None", "value": "None" }, { "name": "keyspace", "type": "str | None", "description": "this is the keyspace to which the collection belongs.\nIf not specified, the database's working keyspace is used.", "default": "None", "value": "None" }, { "name": "namespace", "type": "str | None", "description": "an alias for `keyspace`. *DEPRECATED*, removal in 2.0.", "default": "None", "value": "None" }, { "name": "embedding_api_key", "type": "str | EmbeddingHeadersProvider | None", "description": "optional API key(s) for interacting with the collection.\nIf an embedding service is configured, and this parameter is not None,\neach Data API call will include the necessary embedding-related headers\nas specified by this parameter. If a string is passed, it translates\ninto the one \"embedding api key\" header\n(i.e. `astrapy.authentication.EmbeddingAPIKeyHeaderProvider`).\nFor some vectorize providers/models, if using header-based authentication,\nspecialized subclasses of `astrapy.authentication.EmbeddingHeadersProvider`\nshould be supplied.", "default": "None", "value": "None" }, { "name": "collection_max_time_ms", "type": "int | None", "description": "a default timeout, in millisecond, for the duration of each\noperation on the collection. Individual timeouts can be provided to\neach collection method call and will take precedence, with this value\nbeing an overall default.\nNote that for some methods involving multiple API calls (such as\n`find`, `delete_many`, `insert_many` and so on), it is strongly suggested\nto provide a specific timeout as the default one likely wouldn't make\nmuch sense.", "default": "None", "value": "None" }, { "name": "callers", "type": "Sequence[CallerType]", "description": "a list of caller identities, i.e. applications, or frameworks,\non behalf of which the Data API calls are performed. These end up\nin the request user-agent.\nEach caller identity is a (\"caller_name\", \"caller_version\") pair.", "default": "[]", "value": "[]" }, { "name": "caller_name", "type": "str | None", "description": "*DEPRECATED*, use `callers`. Removal 2.0. Name of the\napplication, or framework, on behalf of which the Data API calls\nare performed. This ends up in the request user-agent.", "default": "None", "value": "None" }, { "name": "caller_version", "type": "str | None", "description": "version of the caller. *DEPRECATED*, use `callers`.\nRemoval 2.0.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "AsyncCollection", "description": "the new copy, an AsyncCollection instance." } ], "gathered_types": [ "astrapy.collection.AsyncCollection", "astrapy.authentication.EmbeddingHeadersProvider", "astrapy.constants.CallerType", "astrapy.database.AsyncDatabase" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> asyncio.run(my_coll.to_async().count_documents({},upper_bound=100))\n77", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.set_caller
Set a new identity for the application/framework on behalf of which the Data API calls are performed (the "caller").
{ "kind": "function", "name": "set_caller", "path": "astrapy.collection.Collection.set_caller", "parameters": [ { "name": "caller_name", "type": "str | None", "description": "name of the application, or framework, on behalf of which\nthe Data API calls are performed. This ends up in the request user-agent.", "default": "None", "value": "None" }, { "name": "caller_version", "type": "str | None", "description": "version of the caller.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "None", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.set_caller(caller_name=\"the_caller\", caller_version=\"0.1.0\")", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.options
Get the collection options, i.e. its configuration as read from the database. The method issues a request to the Data API each time is invoked, without caching mechanisms: this ensures up-to-date information for usages such as real-time collection validation by the application.
{ "kind": "function", "name": "options", "path": "astrapy.collection.Collection.options", "parameters": [ { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "CollectionOptions", "description": "a CollectionOptions instance describing the collection." }, { "name": null, "type": "CollectionOptions", "description": "(See also the database `list_collections` method.)" } ], "gathered_types": [ "astrapy.info.CollectionOptions" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.options()\nCollectionOptions(vector=CollectionVectorOptions(dimension=3, metric='cosine'))", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.info
Information on the collection (name, location, database), in the form of a CollectionInfo object. Not to be confused with the collection `options` method (related to the collection internal configuration).
{ "kind": "function", "name": "info", "path": "astrapy.collection.Collection.info", "parameters": null, "returns": [ { "name": null, "type": "CollectionInfo", "description": null } ], "gathered_types": [ "astrapy.info.CollectionInfo" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.info().database_info.region\n'eu-west-1'\n>>> my_coll.info().full_name\n'default_keyspace.my_v_collection'", "references": null, "note": "the returned CollectionInfo wraps, among other things,\nthe database information: as such, calling this method\ntriggers the same-named method of a Database object (which, in turn,\nperforms a HTTP request to the DevOps API).\nSee the documentation for `Database.info()` for more details.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.database
a Database object, the database this collection belongs to.
{ "kind": "attribute", "name": "database", "path": "astrapy.collection.Collection.database", "parameters": null, "returns": null, "gathered_types": [ "astrapy.database.Database" ], "value": "database: Database", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.database.name\n'the_application_database'", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.namespace
The namespace this collection is in. *DEPRECATED* (removal in 2.0). Switch to the "keyspace" property.**
{ "kind": "attribute", "name": "namespace", "path": "astrapy.collection.Collection.namespace", "parameters": null, "returns": null, "gathered_types": null, "value": "namespace: str", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.namespace\n'default_keyspace'", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.keyspace
The keyspace this collection is in.
{ "kind": "attribute", "name": "keyspace", "path": "astrapy.collection.Collection.keyspace", "parameters": null, "returns": null, "gathered_types": null, "value": "keyspace: str", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.keyspace\n'default_keyspace'", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.name
The name of this collection.
{ "kind": "attribute", "name": "name", "path": "astrapy.collection.Collection.name", "parameters": null, "returns": null, "gathered_types": null, "value": "name: str", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.name\n'my_v_collection'", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.full_name
The fully-qualified collection name within the database, in the form "keyspace.collection_name".
{ "kind": "attribute", "name": "full_name", "path": "astrapy.collection.Collection.full_name", "parameters": null, "returns": null, "gathered_types": null, "value": "full_name: str", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.full_name\n'default_keyspace.my_v_collection'", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.insert_one
Insert a single document in the collection in an atomic operation.
{ "kind": "function", "name": "insert_one", "path": "astrapy.collection.Collection.insert_one", "parameters": [ { "name": "document", "type": "DocumentType", "description": "the dictionary expressing the document to insert.\nThe `_id` field of the document can be left out, in which\ncase it will be created automatically.", "default": null, "value": null }, { "name": "vector", "type": "VectorType | None", "description": "a vector (a list of numbers appropriate for the collection)\nfor the document. Passing this parameter is equivalent to\nproviding a `$vector` field within the document itself,\nhowever the two are mutually exclusive.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the document instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector, if such a service\nis configured for the collection. Passing this parameter is\nequivalent to providing a `$vectorize` field in the document itself,\nhowever the two are mutually exclusive.\nMoreover, this parameter cannot coexist with `vector`.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the document instead.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "InsertOneResult", "description": "an InsertOneResult object." } ], "gathered_types": [ "astrapy.constants.VectorType", "astrapy.constants.DocumentType", "astrapy.results.InsertOneResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.count_documents({}, upper_bound=10)\n0\n>>> my_coll.insert_one(\n... {\n... \"age\": 30,\n... \"name\": \"Smith\",\n... \"food\": [\"pear\", \"peach\"],\n... \"likes_fruit\": True,\n... },\n... )\nInsertOneResult(raw_results=..., inserted_id='ed4587a4-...-...-...')\n>>> my_coll.insert_one({\"_id\": \"user-123\", \"age\": 50, \"name\": \"Maccio\"})\nInsertOneResult(raw_results=..., inserted_id='user-123')\n>>> my_coll.count_documents({}, upper_bound=10)\n2/n/n/n>>> my_coll.insert_one({\"tag\": \"v\", \"$vector\": [10, 11]})\nInsertOneResult(...)", "references": null, "note": "If an `_id` is explicitly provided, which corresponds to a document\nthat exists already in the collection, an error is raised and\nthe insertion fails.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.insert_many
Insert a list of documents into the collection. This is not an atomic operation.
{ "kind": "function", "name": "insert_many", "path": "astrapy.collection.Collection.insert_many", "parameters": [ { "name": "documents", "type": "Iterable[DocumentType]", "description": "an iterable of dictionaries, each a document to insert.\nDocuments may specify their `_id` field or leave it out, in which\ncase it will be added automatically.", "default": null, "value": null }, { "name": "vectors", "type": "Iterable[VectorType | None] | None", "description": "an optional list of vectors (as many vectors as the provided\ndocuments) to associate to the documents when inserting.\nPassing vectors this way is indeed equivalent to the \"$vector\" field\nof the documents, however the two are mutually exclusive.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the documents instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "Iterable[str | None] | None", "description": "an optional list of strings to be made into as many vectors\n(one per document), if such a service is configured for the collection.\nPassing this parameter is equivalent to providing a `$vectorize`\nfield in the documents themselves, however the two are mutually exclusive.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the documents instead.", "default": "None", "value": "None" }, { "name": "ordered", "type": "bool", "description": "if False (default), the insertions can occur in arbitrary order\nand possibly concurrently. If True, they are processed sequentially.\nIf there are no specific reasons against it, unordered insertions are to\nbe preferred as they complete much faster.", "default": "False", "value": "False" }, { "name": "chunk_size", "type": "int | None", "description": "how many documents to include in a single API request.\nExceeding the server maximum allowed value results in an error.\nLeave it unspecified (recommended) to use the system default.", "default": "None", "value": "None" }, { "name": "concurrency", "type": "int | None", "description": "maximum number of concurrent requests to the API at\na given time. It cannot be more than one for ordered insertions.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the operation.\nIf not passed, the collection-level setting is used instead:\nIf many documents are being inserted, this method corresponds\nto several HTTP requests: in such cases one may want to specify\na more tolerant timeout here.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "InsertManyResult", "description": "an InsertManyResult object." } ], "gathered_types": [ "astrapy.constants.VectorType", "astrapy.constants.DocumentType", "astrapy.results.InsertManyResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.count_documents({}, upper_bound=10)\n0\n>>> my_coll.insert_many(\n... [{\"a\": 10}, {\"a\": 5}, {\"b\": [True, False, False]}],\n... ordered=True,\n... )\nInsertManyResult(raw_results=..., inserted_ids=['184bb06f-...', '...', '...'])\n>>> my_coll.count_documents({}, upper_bound=100)\n3\n>>> my_coll.insert_many(\n... [{\"seq\": i} for i in range(50)],\n... concurrency=5,\n... )\nInsertManyResult(raw_results=..., inserted_ids=[... ...])\n>>> my_coll.count_documents({}, upper_bound=100)\n53\n>>> my_coll.insert_many(\n... [\n... {\"tag\": \"a\", \"$vector\": [1, 2]},\n... {\"tag\": \"b\", \"$vector\": [3, 4]},\n... ]\n... )\nInsertManyResult(...)", "references": null, "note": "A failure mode for this command is related to certain faulty documents\nfound among those to insert: a document may have the an `_id` already\npresent on the collection, or its vector dimension may not\nmatch the collection setting.\n\nFor an ordered insertion, the method will raise an exception at\nthe first such faulty document -- nevertheless, all documents processed\nuntil then will end up being written to the database.\n\nFor unordered insertions, if the error stems from faulty documents\nthe insertion proceeds until exhausting the input documents: then,\nan exception is raised -- and all insertable documents will have been\nwritten to the database, including those \"after\" the troublesome ones.\n\nIf, on the other hand, there are errors not related to individual\ndocuments (such as a network connectivity error), the whole\n`insert_many` operation will stop in mid-way, an exception will be raised,\nand only a certain amount of the input documents will\nhave made their way to the database.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.find
Find documents on the collection, matching a certain provided filter. The method returns a Cursor that can then be iterated over. Depending on the method call pattern, the iteration over all documents can reflect collection mutations occurred since the `find` method was called, or not. In cases where the cursor reflects mutations in real-time, it will iterate over cursors in an approximate way (i.e. exhibiting occasional skipped or duplicate documents). This happens when making use of the `sort` option in a non-vector-search manner.
{ "kind": "function", "name": "find", "path": "astrapy.collection.Collection.find", "parameters": [ { "name": "filter", "type": "FilterType | None", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": "None", "value": "None" }, { "name": "projection", "type": "ProjectionType | None", "description": "it controls which parts of the document are returned.\nIt can be an allow-list: `{\"f1\": True, \"f2\": True}`,\nor a deny-list: `{\"fx\": False, \"fy\": False}`, but not a mixture\n(except for the `_id` and other special fields, which can be\nassociated to both True or False independently of the rest\nof the specification).\nThe special star-projections `{\"*\": True}` and `{\"*\": False}`\nhave the effect of returning the whole document and `{}` respectively.\nFor lists in documents, slice directives can be passed to select\nportions of the list: for instance, `{\"array\": {\"$slice\": 2}}`,\n`{\"array\": {\"$slice\": -2}}`, `{\"array\": {\"$slice\": [4, 2]}}` or\n`{\"array\": {\"$slice\": [-4, 2]}}`.\nAn iterable over strings will be treated implicitly as an allow-list.\nThe default projection (used if this parameter is not passed) does not\nnecessarily include \"special\" fields such as `$vector` or `$vectorize`.\nSee the Data API documentation for more on projections.", "default": "None", "value": "None" }, { "name": "skip", "type": "int | None", "description": "with this integer parameter, what would be the first `skip`\ndocuments returned by the query are discarded, and the results\nstart from the (skip+1)-th document.\nThis parameter can be used only in conjunction with an explicit\n`sort` criterion of the ascending/descending type (i.e. it cannot\nbe used when not sorting, nor with vector-based ANN search).", "default": "None", "value": "None" }, { "name": "limit", "type": "int | None", "description": "this (integer) parameter sets a limit over how many documents\nare returned. Once `limit` is reached (or the cursor is exhausted\nfor lack of matching documents), nothing more is returned.", "default": "None", "value": "None" }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to perform vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search).\nWhen running similarity search on a collection, no other sorting\ncriteria can be specified. Moreover, there is an upper bound\nto the number of documents that can be returned. For details,\nsee the Note about upper bounds and the Data API documentation.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nThis can be supplied in (exclusive) alternative to `vector`,\nprovided such a service is configured for the collection,\nand achieves the same effect.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "include_similarity", "type": "bool | None", "description": "a boolean to request the numeric value of the\nsimilarity to be returned as an added \"$similarity\" key in each\nreturned document. Can only be used for vector ANN search, i.e.\nwhen either `vector` is supplied or the `sort` parameter has the\nshape {\"$vector\": ...}.", "default": "None", "value": "None" }, { "name": "include_sort_vector", "type": "bool | None", "description": "a boolean to request query vector used in this search.\nIf set to True (and if the invocation is a vector search), calling\nthe `get_sort_vector` method on the returned cursor will yield\nthe vector used for the ANN search.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the order\nthe documents are returned. See the Note about sorting, as well as\nthe one about upper bounds, for details.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for each single one\nof the underlying HTTP requests used to fetch documents as the\ncursor is iterated over.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "Cursor", "description": "a Cursor object representing iterations over the matching documents" }, { "name": null, "type": "Cursor", "description": "(see the Cursor object for how to use it. The simplest thing is to" }, { "name": null, "type": "Cursor", "description": "run a for loop: `for document in collection.sort(...):`)." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.VectorType", "astrapy.cursors.Cursor", "astrapy.constants.ProjectionType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> filter = {\"seq\": {\"$exists\": True}}\n>>> for doc in my_coll.find(filter, projection={\"seq\": True}, limit=5):\n... print(doc[\"seq\"])\n...\n37\n35\n10\n36\n27\n>>> cursor1 = my_coll.find(\n... {},\n... limit=4,\n... sort={\"seq\": astrapy.constants.SortDocuments.DESCENDING},\n... )\n>>> [doc[\"_id\"] for doc in cursor1]\n['97e85f81-...', '1581efe4-...', '...', '...']\n>>> cursor2 = my_coll.find({}, limit=3)\n>>> cursor2.distinct(\"seq\")\n[37, 35, 10]/n/n/n>>> my_coll.insert_many([\n... {\"tag\": \"A\", \"$vector\": [4, 5]},\n... {\"tag\": \"B\", \"$vector\": [3, 4]},\n... {\"tag\": \"C\", \"$vector\": [3, 2]},\n... {\"tag\": \"D\", \"$vector\": [4, 1]},\n... {\"tag\": \"E\", \"$vector\": [2, 5]},\n... ])\n>>> ann_tags = [\n... document[\"tag\"]\n... for document in my_coll.find(\n... {},\n... sort={\"$vector\": [3, 3]},\n... limit=3,\n... )\n... ]\n>>> ann_tags\n['A', 'B', 'C']\n>>> # (assuming the collection has metric VectorMetric.COSINE)/n/n/n>>> cursor = my_coll.find(\n... sort={\"$vector\": [3, 3]},\n... limit=3,\n... include_sort_vector=True,\n... )\n>>> cursor.get_sort_vector()\n[3.0, 3.0]\n>>> matches = list(cursor)\n>>> cursor.get_sort_vector()\n[3.0, 3.0]", "references": null, "note": "When not specifying sorting criteria at all (by vector or otherwise),\nthe cursor can scroll through an arbitrary number of documents as\nthe Data API and the client periodically exchange new chunks of documents.\nIt should be noted that the behavior of the cursor in the case documents\nhave been added/removed after the `find` was started depends on database\ninternals and it is not guaranteed, nor excluded, that such \"real-time\"\nchanges in the data would be picked up by the cursor.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.find_one
Run a search, returning the first document in the collection that matches provided filters, if any is found.
{ "kind": "function", "name": "find_one", "path": "astrapy.collection.Collection.find_one", "parameters": [ { "name": "filter", "type": "FilterType | None", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": "None", "value": "None" }, { "name": "projection", "type": "ProjectionType | None", "description": "it controls which parts of the document are returned.\nIt can be an allow-list: `{\"f1\": True, \"f2\": True}`,\nor a deny-list: `{\"fx\": False, \"fy\": False}`, but not a mixture\n(except for the `_id` and other special fields, which can be\nassociated to both True or False independently of the rest\nof the specification).\nThe special star-projections `{\"*\": True}` and `{\"*\": False}`\nhave the effect of returning the whole document and `{}` respectively.\nFor lists in documents, slice directives can be passed to select\nportions of the list: for instance, `{\"array\": {\"$slice\": 2}}`,\n`{\"array\": {\"$slice\": -2}}`, `{\"array\": {\"$slice\": [4, 2]}}` or\n`{\"array\": {\"$slice\": [-4, 2]}}`.\nAn iterable over strings will be treated implicitly as an allow-list.\nThe default projection (used if this parameter is not passed) does not\nnecessarily include \"special\" fields such as `$vector` or `$vectorize`.\nSee the Data API documentation for more on projections.", "default": "None", "value": "None" }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to perform vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), extracting the most\nsimilar document in the collection matching the filter.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nUsing vectorize assumes a suitable service is configured for the collection.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "include_similarity", "type": "bool | None", "description": "a boolean to request the numeric value of the\nsimilarity to be returned as an added \"$similarity\" key in the\nreturned document. Can only be used for vector ANN search, i.e.\nwhen either `vector` is supplied or the `sort` parameter has the\nshape {\"$vector\": ...}.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the order\nthe documents are returned. See the Note about sorting for details.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "DocumentType | None", "description": "a dictionary expressing the required document, otherwise None." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.DocumentType", "astrapy.constants.VectorType", "astrapy.constants.ProjectionType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.find_one({})\n{'_id': '68d1e515-...', 'seq': 37}\n>>> my_coll.find_one({\"seq\": 10})\n{'_id': 'd560e217-...', 'seq': 10}\n>>> my_coll.find_one({\"seq\": 1011})\n>>> # (returns None for no matches)\n>>> my_coll.find_one({}, projection={\"seq\": False})\n{'_id': '68d1e515-...'}\n>>> my_coll.find_one(\n... {},\n... sort={\"seq\": astrapy.constants.SortDocuments.DESCENDING},\n... )\n{'_id': '97e85f81-...', 'seq': 69}\n>>> my_coll.find_one({}, sort={\"$vector\": [1, 0]}, projection={\"*\": True})\n{'_id': '...', 'tag': 'D', '$vector': [4.0, 1.0]}", "references": null, "note": "See the `find` method for more details on the accepted parameters\n(whereas `skip` and `limit` are not valid parameters for `find_one`).", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.distinct
Return a list of the unique values of `key` across the documents in the collection that match the provided filter.
{ "kind": "function", "name": "distinct", "path": "astrapy.collection.Collection.distinct", "parameters": [ { "name": "key", "type": "str", "description": "the name of the field whose value is inspected across documents.\nKeys can use dot-notation to descend to deeper document levels.\nExample of acceptable `key` values:\n \"field\"\n \"field.subfield\"\n \"field.3\"\n \"field.3.subfield\"\nIf lists are encountered and no numeric index is specified,\nall items in the list are visited.", "default": null, "value": null }, { "name": "filter", "type": "FilterType | None", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, with the same meaning as for `find`.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "list[Any]", "description": "a list of all different values for `key` found across the documents" }, { "name": null, "type": "list[Any]", "description": "that match the filter. The result list has no repeated items." } ], "gathered_types": [ "astrapy.constants.FilterType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.insert_many(\n... [\n... {\"name\": \"Marco\", \"food\": [\"apple\", \"orange\"], \"city\": \"Helsinki\"},\n... {\"name\": \"Emma\", \"food\": {\"likes_fruit\": True, \"allergies\": []}},\n... ]\n... )\nInsertManyResult(raw_results=..., inserted_ids=['c5b99f37-...', 'd6416321-...'])\n>>> my_coll.distinct(\"name\")\n['Marco', 'Emma']\n>>> my_coll.distinct(\"city\")\n['Helsinki']\n>>> my_coll.distinct(\"food\")\n['apple', 'orange', {'likes_fruit': True, 'allergies': []}]\n>>> my_coll.distinct(\"food.1\")\n['orange']\n>>> my_coll.distinct(\"food.allergies\")\n[]\n>>> my_coll.distinct(\"food.likes_fruit\")\n[True]", "references": null, "note": "For details on the behaviour of \"distinct\" in conjunction with\nreal-time changes in the collection contents, see the\nNote of the `find` command.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.count_documents
Count the documents in the collection matching the specified filter.
{ "kind": "function", "name": "count_documents", "path": "astrapy.collection.Collection.count_documents", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "upper_bound", "type": "int", "description": "a required ceiling on the result of the count operation.\nIf the actual number of documents exceeds this value,\nan exception will be raised.\nFurthermore, if the actual number of documents exceeds the maximum\ncount that the Data API can reach (regardless of upper_bound),\nan exception will be raised.", "default": null, "value": null }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "int", "description": "the exact count of matching documents." } ], "gathered_types": [ "astrapy.constants.FilterType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.insert_many([{\"seq\": i} for i in range(20)])\nInsertManyResult(...)\n>>> my_coll.count_documents({}, upper_bound=100)\n20\n>>> my_coll.count_documents({\"seq\":{\"$gt\": 15}}, upper_bound=100)\n4\n>>> my_coll.count_documents({}, upper_bound=10)\nTraceback (most recent call last):\n ... ...\nastrapy.exceptions.TooManyDocumentsToCountException", "references": null, "note": "Count operations are expensive: for this reason, the best practice\nis to provide a reasonable `upper_bound` according to the caller\nexpectations. Moreover, indiscriminate usage of count operations\nfor sizeable amounts of documents (i.e. in the thousands and more)\nis discouraged in favor of alternative application-specific solutions.\nKeep in mind that the Data API has a hard upper limit on the amount\nof documents it will count, and that an exception will be thrown\nby this method if this limit is encountered.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.estimated_document_count
Query the API server for an estimate of the document count in the collection. Contrary to `count_documents`, this method has no filtering parameters.
{ "kind": "function", "name": "estimated_document_count", "path": "astrapy.collection.Collection.estimated_document_count", "parameters": [ { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "int", "description": "a server-provided estimate count of the documents in the collection." } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.estimated_document_count()\n35700", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.find_one_and_replace
Find a document on the collection and replace it entirely with a new one, optionally inserting a new one if no match is found.
{ "kind": "function", "name": "find_one_and_replace", "path": "astrapy.collection.Collection.find_one_and_replace", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "replacement", "type": "DocumentType", "description": "the new document to write into the collection.", "default": null, "value": null }, { "name": "projection", "type": "ProjectionType | None", "description": "it controls which parts of the document are returned.\nIt can be an allow-list: `{\"f1\": True, \"f2\": True}`,\nor a deny-list: `{\"fx\": False, \"fy\": False}`, but not a mixture\n(except for the `_id` and other special fields, which can be\nassociated to both True or False independently of the rest\nof the specification).\nThe special star-projections `{\"*\": True}` and `{\"*\": False}`\nhave the effect of returning the whole document and `{}` respectively.\nFor lists in documents, slice directives can be passed to select\nportions of the list: for instance, `{\"array\": {\"$slice\": 2}}`,\n`{\"array\": {\"$slice\": -2}}`, `{\"array\": {\"$slice\": [4, 2]}}` or\n`{\"array\": {\"$slice\": [-4, 2]}}`.\nAn iterable over strings will be treated implicitly as an allow-list.\nThe default projection (used if this parameter is not passed) does not\nnecessarily include \"special\" fields such as `$vector` or `$vectorize`.\nSee the Data API documentation for more on projections.", "default": "None", "value": "None" }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to use vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), as the sorting criterion.\nIn this way, the matched document (if any) will be the one\nthat is most similar to the provided vector.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nUsing vectorize assumes a suitable service is configured for the collection.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the sorting\norder of the documents matching the filter, effectively\ndetermining what document will come first and hence be the\nreplaced one. See the `find` method for more on sorting.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "upsert", "type": "bool", "description": "this parameter controls the behavior in absence of matches.\nIf True, `replacement` is inserted as a new document\nif no matches are found on the collection. If False,\nthe operation silently does nothing in case of no matches.", "default": "False", "value": "False" }, { "name": "return_document", "type": "str", "description": "a flag controlling what document is returned:\nif set to `ReturnDocument.BEFORE`, or the string \"before\",\nthe document found on database is returned; if set to\n`ReturnDocument.AFTER`, or the string \"after\", the new\ndocument is returned. The default is \"before\".", "default": "ReturnDocument.BEFORE", "value": "ReturnDocument.BEFORE" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "DocumentType | None", "description": "A document (or a projection thereof, as required), either the one" }, { "name": null, "type": "DocumentType | None", "description": "before the replace operation or the one after that." }, { "name": null, "type": "DocumentType | None", "description": "Alternatively, the method returns None to represent" }, { "name": null, "type": "DocumentType | None", "description": "that no matching document was found, or that no replacement" }, { "name": null, "type": "DocumentType | None", "description": "was inserted (depending on the `return_document` parameter)." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.ReturnDocument", "astrapy.constants.DocumentType", "astrapy.constants.VectorType", "BEFORE", "astrapy.constants.ProjectionType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.insert_one({\"_id\": \"rule1\", \"text\": \"all animals are equal\"})\nInsertOneResult(...)\n>>> my_coll.find_one_and_replace(\n... {\"_id\": \"rule1\"},\n... {\"text\": \"some animals are more equal!\"},\n... )\n{'_id': 'rule1', 'text': 'all animals are equal'}\n>>> my_coll.find_one_and_replace(\n... {\"text\": \"some animals are more equal!\"},\n... {\"text\": \"and the pigs are the rulers\"},\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... )\n{'_id': 'rule1', 'text': 'and the pigs are the rulers'}\n>>> my_coll.find_one_and_replace(\n... {\"_id\": \"rule2\"},\n... {\"text\": \"F=ma^2\"},\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... )\n>>> # (returns None for no matches)\n>>> my_coll.find_one_and_replace(\n... {\"_id\": \"rule2\"},\n... {\"text\": \"F=ma\"},\n... upsert=True,\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... projection={\"_id\": False},\n... )\n{'text': 'F=ma'}", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.replace_one
Replace a single document on the collection with a new one, optionally inserting a new one if no match is found.
{ "kind": "function", "name": "replace_one", "path": "astrapy.collection.Collection.replace_one", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "replacement", "type": "DocumentType", "description": "the new document to write into the collection.", "default": null, "value": null }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to use vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), as the sorting criterion.\nIn this way, the matched document (if any) will be the one\nthat is most similar to the provided vector.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nUsing vectorize assumes a suitable service is configured for the collection.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the sorting\norder of the documents matching the filter, effectively\ndetermining what document will come first and hence be the\nreplaced one. See the `find` method for more on sorting.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "upsert", "type": "bool", "description": "this parameter controls the behavior in absence of matches.\nIf True, `replacement` is inserted as a new document\nif no matches are found on the collection. If False,\nthe operation silently does nothing in case of no matches.", "default": "False", "value": "False" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "UpdateResult", "description": "an UpdateResult object summarizing the outcome of the replace operation." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.DocumentType", "astrapy.results.UpdateResult", "astrapy.constants.VectorType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.insert_one({\"Marco\": \"Polo\"})\nInsertOneResult(...)\n>>> my_coll.replace_one({\"Marco\": {\"$exists\": True}}, {\"Buda\": \"Pest\"})\nUpdateResult(raw_results=..., update_info={'n': 1, 'updatedExisting': True, 'ok': 1.0, 'nModified': 1})\n>>> my_coll.find_one({\"Buda\": \"Pest\"})\n{'_id': '8424905a-...', 'Buda': 'Pest'}\n>>> my_coll.replace_one({\"Mirco\": {\"$exists\": True}}, {\"Oh\": \"yeah?\"})\nUpdateResult(raw_results=..., update_info={'n': 0, 'updatedExisting': False, 'ok': 1.0, 'nModified': 0})\n>>> my_coll.replace_one({\"Mirco\": {\"$exists\": True}}, {\"Oh\": \"yeah?\"}, upsert=True)\nUpdateResult(raw_results=..., update_info={'n': 1, 'updatedExisting': False, 'ok': 1.0, 'nModified': 0, 'upserted': '931b47d6-...'})", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.find_one_and_update
Find a document on the collection and update it as requested, optionally inserting a new one if no match is found.
{ "kind": "function", "name": "find_one_and_update", "path": "astrapy.collection.Collection.find_one_and_update", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "update", "type": "dict[str, Any]", "description": "the update prescription to apply to the document, expressed\nas a dictionary as per Data API syntax. Examples are:\n {\"$set\": {\"field\": \"value}}\n {\"$inc\": {\"counter\": 10}}\n {\"$unset\": {\"field\": \"\"}}\nSee the Data API documentation for the full syntax.", "default": null, "value": null }, { "name": "projection", "type": "ProjectionType | None", "description": "it controls which parts of the document are returned.\nIt can be an allow-list: `{\"f1\": True, \"f2\": True}`,\nor a deny-list: `{\"fx\": False, \"fy\": False}`, but not a mixture\n(except for the `_id` and other special fields, which can be\nassociated to both True or False independently of the rest\nof the specification).\nThe special star-projections `{\"*\": True}` and `{\"*\": False}`\nhave the effect of returning the whole document and `{}` respectively.\nFor lists in documents, slice directives can be passed to select\nportions of the list: for instance, `{\"array\": {\"$slice\": 2}}`,\n`{\"array\": {\"$slice\": -2}}`, `{\"array\": {\"$slice\": [4, 2]}}` or\n`{\"array\": {\"$slice\": [-4, 2]}}`.\nAn iterable over strings will be treated implicitly as an allow-list.\nThe default projection (used if this parameter is not passed) does not\nnecessarily include \"special\" fields such as `$vector` or `$vectorize`.\nSee the Data API documentation for more on projections.", "default": "None", "value": "None" }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to use vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), as the sorting criterion.\nIn this way, the matched document (if any) will be the one\nthat is most similar to the provided vector.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nUsing vectorize assumes a suitable service is configured for the collection.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the sorting\norder of the documents matching the filter, effectively\ndetermining what document will come first and hence be the\nreplaced one. See the `find` method for more on sorting.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "upsert", "type": "bool", "description": "this parameter controls the behavior in absence of matches.\nIf True, a new document (resulting from applying the `update`\nto an empty document) is inserted if no matches are found on\nthe collection. If False, the operation silently does nothing\nin case of no matches.", "default": "False", "value": "False" }, { "name": "return_document", "type": "str", "description": "a flag controlling what document is returned:\nif set to `ReturnDocument.BEFORE`, or the string \"before\",\nthe document found on database is returned; if set to\n`ReturnDocument.AFTER`, or the string \"after\", the new\ndocument is returned. The default is \"before\".", "default": "ReturnDocument.BEFORE", "value": "ReturnDocument.BEFORE" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "DocumentType | None", "description": "A document (or a projection thereof, as required), either the one" }, { "name": null, "type": "DocumentType | None", "description": "before the replace operation or the one after that." }, { "name": null, "type": "DocumentType | None", "description": "Alternatively, the method returns None to represent" }, { "name": null, "type": "DocumentType | None", "description": "that no matching document was found, or that no update" }, { "name": null, "type": "DocumentType | None", "description": "was applied (depending on the `return_document` parameter)." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.ReturnDocument", "astrapy.constants.DocumentType", "astrapy.constants.VectorType", "BEFORE", "astrapy.constants.ProjectionType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.insert_one({\"Marco\": \"Polo\"})\nInsertOneResult(...)\n>>> my_coll.find_one_and_update(\n... {\"Marco\": {\"$exists\": True}},\n... {\"$set\": {\"title\": \"Mr.\"}},\n... )\n{'_id': 'a80106f2-...', 'Marco': 'Polo'}\n>>> my_coll.find_one_and_update(\n... {\"title\": \"Mr.\"},\n... {\"$inc\": {\"rank\": 3}},\n... projection=[\"title\", \"rank\"],\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... )\n{'_id': 'a80106f2-...', 'title': 'Mr.', 'rank': 3}\n>>> my_coll.find_one_and_update(\n... {\"name\": \"Johnny\"},\n... {\"$set\": {\"rank\": 0}},\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... )\n>>> # (returns None for no matches)\n>>> my_coll.find_one_and_update(\n... {\"name\": \"Johnny\"},\n... {\"$set\": {\"rank\": 0}},\n... upsert=True,\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... )\n{'_id': 'cb4ef2ab-...', 'name': 'Johnny', 'rank': 0}", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.update_one
Update a single document on the collection as requested, optionally inserting a new one if no match is found.
{ "kind": "function", "name": "update_one", "path": "astrapy.collection.Collection.update_one", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "update", "type": "dict[str, Any]", "description": "the update prescription to apply to the document, expressed\nas a dictionary as per Data API syntax. Examples are:\n {\"$set\": {\"field\": \"value}}\n {\"$inc\": {\"counter\": 10}}\n {\"$unset\": {\"field\": \"\"}}\nSee the Data API documentation for the full syntax.", "default": null, "value": null }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to use vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), as the sorting criterion.\nIn this way, the matched document (if any) will be the one\nthat is most similar to the provided vector.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nUsing vectorize assumes a suitable service is configured for the collection.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the sorting\norder of the documents matching the filter, effectively\ndetermining what document will come first and hence be the\nreplaced one. See the `find` method for more on sorting.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "upsert", "type": "bool", "description": "this parameter controls the behavior in absence of matches.\nIf True, a new document (resulting from applying the `update`\nto an empty document) is inserted if no matches are found on\nthe collection. If False, the operation silently does nothing\nin case of no matches.", "default": "False", "value": "False" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "UpdateResult", "description": "an UpdateResult object summarizing the outcome of the update operation." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.VectorType", "astrapy.results.UpdateResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.insert_one({\"Marco\": \"Polo\"})\nInsertOneResult(...)\n>>> my_coll.update_one({\"Marco\": {\"$exists\": True}}, {\"$inc\": {\"rank\": 3}})\nUpdateResult(raw_results=..., update_info={'n': 1, 'updatedExisting': True, 'ok': 1.0, 'nModified': 1})\n>>> my_coll.update_one({\"Mirko\": {\"$exists\": True}}, {\"$inc\": {\"rank\": 3}})\nUpdateResult(raw_results=..., update_info={'n': 0, 'updatedExisting': False, 'ok': 1.0, 'nModified': 0})\n>>> my_coll.update_one({\"Mirko\": {\"$exists\": True}}, {\"$inc\": {\"rank\": 3}}, upsert=True)\nUpdateResult(raw_results=..., update_info={'n': 1, 'updatedExisting': False, 'ok': 1.0, 'nModified': 0, 'upserted': '2a45ff60-...'})", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.update_many
Apply an update operations to all documents matching a condition, optionally inserting one documents in absence of matches.
{ "kind": "function", "name": "update_many", "path": "astrapy.collection.Collection.update_many", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "update", "type": "dict[str, Any]", "description": "the update prescription to apply to the documents, expressed\nas a dictionary as per Data API syntax. Examples are:\n {\"$set\": {\"field\": \"value}}\n {\"$inc\": {\"counter\": 10}}\n {\"$unset\": {\"field\": \"\"}}\nSee the Data API documentation for the full syntax.", "default": null, "value": null }, { "name": "upsert", "type": "bool", "description": "this parameter controls the behavior in absence of matches.\nIf True, a single new document (resulting from applying `update`\nto an empty document) is inserted if no matches are found on\nthe collection. If False, the operation silently does nothing\nin case of no matches.", "default": "False", "value": "False" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the operation.\nIf not passed, the collection-level setting is used instead:\nif a large number of document updates is anticipated, it is suggested\nto specify a larger timeout than in most other operations as the\nupdate will span several HTTP calls to the API in sequence.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "UpdateResult", "description": "an UpdateResult object summarizing the outcome of the update operation." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.results.UpdateResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.insert_many([{\"c\": \"red\"}, {\"c\": \"green\"}, {\"c\": \"blue\"}])\nInsertManyResult(...)\n>>> my_coll.update_many({\"c\": {\"$ne\": \"green\"}}, {\"$set\": {\"nongreen\": True}})\nUpdateResult(raw_results=..., update_info={'n': 2, 'updatedExisting': True, 'ok': 1.0, 'nModified': 2})\n>>> my_coll.update_many({\"c\": \"orange\"}, {\"$set\": {\"is_also_fruit\": True}})\nUpdateResult(raw_results=..., update_info={'n': 0, 'updatedExisting': False, 'ok': 1.0, 'nModified': 0})\n>>> my_coll.update_many(\n... {\"c\": \"orange\"},\n... {\"$set\": {\"is_also_fruit\": True}},\n... upsert=True,\n... )\nUpdateResult(raw_results=..., update_info={'n': 1, 'updatedExisting': False, 'ok': 1.0, 'nModified': 0, 'upserted': '46643050-...'})", "references": null, "note": "Similarly to the case of `find` (see its docstring for more details),\nrunning this command while, at the same time, another process is\ninserting new documents which match the filter of the `update_many`\ncan result in an unpredictable fraction of these documents being updated.\nIn other words, it cannot be easily predicted whether a given\nnewly-inserted document will be picked up by the update_many command or not.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.find_one_and_delete
Find a document in the collection and delete it. The deleted document, however, is the return value of the method.
{ "kind": "function", "name": "find_one_and_delete", "path": "astrapy.collection.Collection.find_one_and_delete", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "projection", "type": "ProjectionType | None", "description": "it controls which parts of the document are returned.\nIt can be an allow-list: `{\"f1\": True, \"f2\": True}`,\nor a deny-list: `{\"fx\": False, \"fy\": False}`, but not a mixture\n(except for the `_id` and other special fields, which can be\nassociated to both True or False independently of the rest\nof the specification).\nThe special star-projections `{\"*\": True}` and `{\"*\": False}`\nhave the effect of returning the whole document and `{}` respectively.\nFor lists in documents, slice directives can be passed to select\nportions of the list: for instance, `{\"array\": {\"$slice\": 2}}`,\n`{\"array\": {\"$slice\": -2}}`, `{\"array\": {\"$slice\": [4, 2]}}` or\n`{\"array\": {\"$slice\": [-4, 2]}}`.\nAn iterable over strings will be treated implicitly as an allow-list.\nThe default projection (used if this parameter is not passed) does not\nnecessarily include \"special\" fields such as `$vector` or `$vectorize`.\nSee the Data API documentation for more on projections.", "default": "None", "value": "None" }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to use vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), as the sorting criterion.\nIn this way, the matched document (if any) will be the one\nthat is most similar to the provided vector.\nThis parameter cannot be used together with `sort`.\nSee the `find` method for more details on this parameter.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nThis can be supplied in (exclusive) alternative to `vector`,\nprovided such a service is configured for the collection,\nand achieves the same effect.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the sorting\norder of the documents matching the filter, effectively\ndetermining what document will come first and hence be the\ndeleted one. See the `find` method for more on sorting.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "DocumentType | None", "description": "Either the document (or a projection thereof, as requested), or None" }, { "name": null, "type": "DocumentType | None", "description": "if no matches were found in the first place." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.DocumentType", "astrapy.constants.VectorType", "astrapy.constants.ProjectionType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.insert_many(\n... [\n... {\"species\": \"swan\", \"class\": \"Aves\"},\n... {\"species\": \"frog\", \"class\": \"Amphibia\"},\n... ],\n... )\nInsertManyResult(...)\n>>> my_coll.find_one_and_delete(\n... {\"species\": {\"$ne\": \"frog\"}},\n... projection=[\"species\"],\n... )\n{'_id': '5997fb48-...', 'species': 'swan'}\n>>> my_coll.find_one_and_delete({\"species\": {\"$ne\": \"frog\"}})\n>>> # (returns None for no matches)", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.delete_one
Delete one document matching a provided filter. This method never deletes more than a single document, regardless of the number of matches to the provided filters.
{ "kind": "function", "name": "delete_one", "path": "astrapy.collection.Collection.delete_one", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to use vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), as the sorting criterion.\nIn this way, the matched document (if any) will be the one\nthat is most similar to the provided vector.\nThis parameter cannot be used together with `sort`.\nSee the `find` method for more details on this parameter.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nThis can be supplied in (exclusive) alternative to `vector`,\nprovided such a service is configured for the collection,\nand achieves the same effect.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the sorting\norder of the documents matching the filter, effectively\ndetermining what document will come first and hence be the\ndeleted one. See the `find` method for more on sorting.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "DeleteResult", "description": "a DeleteResult object summarizing the outcome of the delete operation." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.VectorType", "astrapy.results.DeleteResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.insert_many([{\"seq\": 1}, {\"seq\": 0}, {\"seq\": 2}])\nInsertManyResult(...)\n>>> my_coll.delete_one({\"seq\": 1})\nDeleteResult(raw_results=..., deleted_count=1)\n>>> my_coll.distinct(\"seq\")\n[0, 2]\n>>> my_coll.delete_one(\n... {\"seq\": {\"$exists\": True}},\n... sort={\"seq\": astrapy.constants.SortDocuments.DESCENDING},\n... )\nDeleteResult(raw_results=..., deleted_count=1)\n>>> my_coll.distinct(\"seq\")\n[0]\n>>> my_coll.delete_one({\"seq\": 2})\nDeleteResult(raw_results=..., deleted_count=0)", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.delete_many
Delete all documents matching a provided filter.
{ "kind": "function", "name": "delete_many", "path": "astrapy.collection.Collection.delete_many", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.\nPassing an empty filter, `{}`, completely erases all contents\nof the collection.", "default": null, "value": null }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the operation.\nIf not passed, the collection-level setting is used instead:\nkeep in mind that this method entails successive HTTP requests\nto the API, depending on how many documents are to be deleted.\nFor this reason, in most cases it is suggested to relax the\ntimeout compared to other method calls.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "DeleteResult", "description": "a DeleteResult object summarizing the outcome of the delete operation." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.results.DeleteResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.insert_many([{\"seq\": 1}, {\"seq\": 0}, {\"seq\": 2}])\nInsertManyResult(...)\n>>> my_coll.delete_many({\"seq\": {\"$lte\": 1}})\nDeleteResult(raw_results=..., deleted_count=2)\n>>> my_coll.distinct(\"seq\")\n[2]\n>>> my_coll.delete_many({\"seq\": {\"$lte\": 1}})\nDeleteResult(raw_results=..., deleted_count=0)", "references": null, "note": "This operation is in general not atomic. Depending on the amount\nof matching documents, it can keep running (in a blocking way)\nfor a macroscopic time. In that case, new documents that are\nmeanwhile inserted (e.g. from another process/application) will be\ndeleted during the execution of this method call until the\ncollection is devoid of matches.\nAn exception is the `filter={}` case, whereby the operation is atomic.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.delete_all
Delete all documents in a collection.
{ "kind": "function", "name": "delete_all", "path": "astrapy.collection.Collection.delete_all", "parameters": [ { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "dict[str, Any]", "description": "a dictionary of the form {\"ok\": 1} to signal successful deletion." } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.distinct(\"seq\")\n[2, 1, 0]\n>>> my_coll.count_documents({}, upper_bound=100)\n4\n>>> my_coll.delete_all()\n{'ok': 1}\n>>> my_coll.count_documents({}, upper_bound=100)\n0", "references": null, "note": "Use with caution.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.bulk_write
Execute an arbitrary amount of operations such as inserts, updates, deletes either sequentially or concurrently. This method does not execute atomically, i.e. individual operations are each performed in the same way as the corresponding collection method, and each one is a different and unrelated database mutation.
{ "kind": "function", "name": "bulk_write", "path": "astrapy.collection.Collection.bulk_write", "parameters": [ { "name": "requests", "type": "Iterable[BaseOperation]", "description": "an iterable over concrete subclasses of `BaseOperation`,\nsuch as `InsertMany` or `ReplaceOne`. Each such object\nrepresents an operation ready to be executed on a collection,\nand is instantiated by passing the same parameters as one\nwould the corresponding collection method.", "default": null, "value": null }, { "name": "ordered", "type": "bool", "description": "whether to launch the `requests` one after the other or\nin arbitrary order, possibly in a concurrent fashion. For\nperformance reasons, False (default) should be preferred\nwhen compatible with the needs of the application flow.", "default": "False", "value": "False" }, { "name": "concurrency", "type": "int | None", "description": "maximum number of concurrent operations executing at\na given time. It cannot be more than one for ordered bulk writes.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the whole bulk write.\nRemember that, if the method call times out, then there's no\nguarantee about what portion of the bulk write has been received\nand successfully executed by the Data API.\nIf not passed, the collection-level setting is used instead:\nin most cases, however, one should pass a relaxed timeout\nif longer sequences of operations are to be executed in bulk.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "BulkWriteResult", "description": "A single BulkWriteResult summarizing the whole list of requested" }, { "name": null, "type": "BulkWriteResult", "description": "operations. The keys in the map attributes of BulkWriteResult" }, { "name": null, "type": "BulkWriteResult", "description": "(when present) are the integer indices of the corresponding operation" }, { "name": null, "type": "BulkWriteResult", "description": "in the `requests` iterable." } ], "gathered_types": [ "astrapy.results.BulkWriteResult", "astrapy.operations.BaseOperation" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> from astrapy.operations import InsertMany, ReplaceOne\n>>> op1 = InsertMany([{\"a\": 1}, {\"a\": 2}])\n>>> op2 = ReplaceOne({\"z\": 9}, replacement={\"z\": 9, \"replaced\": True}, upsert=True)\n>>> my_coll.bulk_write([op1, op2])\nBulkWriteResult(bulk_api_results={0: ..., 1: ...}, deleted_count=0, inserted_count=3, matched_count=0, modified_count=0, upserted_count=1, upserted_ids={1: '2addd676-...'})\n>>> my_coll.count_documents({}, upper_bound=100)\n3\n>>> my_coll.distinct(\"replaced\")\n[True]", "references": [ "astrapy.operations.ReplaceOne", "astrapy.operations.InsertMany" ], "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.Collection.drop
Drop the collection, i.e. delete it from the database along with all the documents it contains.
{ "kind": "function", "name": "drop", "path": "astrapy.collection.Collection.drop", "parameters": [ { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.\nRemember there is not guarantee that a request that has\ntimed out us not in fact honored.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "dict[str, Any]", "description": "a dictionary of the form {\"ok\": 1} to signal successful deletion." } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.find_one({})\n{'_id': '...', 'a': 100}\n>>> my_coll.drop()\n{'ok': 1}\n>>> my_coll.find_one({})\nTraceback (most recent call last):\n ... ...\nastrapy.exceptions.DataAPIResponseException: Collection does not exist, collection name: my_collection", "references": null, "note": "Once the method succeeds, methods on this object can still be invoked:\nhowever, this hardly makes sense as the underlying actual collection\nis no more.\nIt is responsibility of the developer to design a correct flow\nwhich avoids using a deceased collection any further.", "implemented_by": null, "attributes": null }
astrapy.collection.Collection.command
Send a POST request to the Data API for this collection with an arbitrary, caller-provided payload.
{ "kind": "function", "name": "command", "path": "astrapy.collection.Collection.command", "parameters": [ { "name": "body", "type": "dict[str, Any]", "description": "a JSON-serializable dictionary, the payload of the request.", "default": null, "value": null }, { "name": "raise_api_errors", "type": "bool", "description": "if True, responses with a nonempty 'errors' field\nresult in an astrapy exception being raised.", "default": "True", "value": "True" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "dict[str, Any]", "description": "a dictionary with the response of the HTTP request." } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.command({\"countDocuments\": {}})\n{'status': {'count': 123}}", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection
A Data API collection, the main object to interact with the Data API, especially for DDL operations. This class has an asynchronous interface for use with asyncio. An AsyncCollection is spawned from a Database object, from which it inherits the details on how to reach the API server (endpoint, authentication token).
{ "kind": "class", "name": "AsyncCollection", "path": "astrapy.collection.AsyncCollection", "parameters": [ { "name": "database", "type": "AsyncDatabase", "description": "a Database object, instantiated earlier. This represents\nthe database the collection belongs to.", "default": null, "value": null }, { "name": "name", "type": "str", "description": "the collection name. This parameter should match an existing\ncollection on the database.", "default": null, "value": null }, { "name": "keyspace", "type": "str | None", "description": "this is the keyspace to which the collection belongs.\nIf not specified, the database's working keyspace is used.", "default": "None", "value": "None" }, { "name": "namespace", "type": "str | None", "description": "an alias for `keyspace`. *DEPRECATED*, removal in 2.0.", "default": "None", "value": "None" }, { "name": "api_options", "type": "CollectionAPIOptions | None", "description": "An instance of `astrapy.api_options.CollectionAPIOptions`\nproviding the general settings for interacting with the Data API.", "default": "None", "value": "None" }, { "name": "callers", "type": "Sequence[CallerType]", "description": "a list of caller identities, i.e. applications, or frameworks,\non behalf of which the Data API calls are performed. These end up\nin the request user-agent.\nEach caller identity is a (\"caller_name\", \"caller_version\") pair.", "default": "[]", "value": "[]" }, { "name": "caller_name", "type": "str | None", "description": "*DEPRECATED*, use `callers`. Removal 2.0. Name of the\napplication, or framework, on behalf of which the Data API calls\nare performed. This ends up in the request user-agent.", "default": "None", "value": "None" }, { "name": "caller_version", "type": "str | None", "description": "version of the caller. *DEPRECATED*, use `callers`. Removal 2.0.", "default": "None", "value": "None" } ], "returns": null, "gathered_types": [ "astrapy.constants.CallerType", "astrapy.api_options.CollectionAPIOptions", "astrapy.database.AsyncDatabase" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> from astrapy import DataAPIClient, AsyncCollection\n>>> my_client = astrapy.DataAPIClient(\"AstraCS:...\")\n>>> my_async_db = my_client.get_async_database(\n... \"https://01234567-....apps.astra.datastax.com\"\n... )\n>>> my_async_coll_1 = AsyncCollection(database=my_async_db, name=\"my_collection\")\n>>> my_async coll_2 = asyncio.run(my_async_db.create_collection(\n... \"my_v_collection\",\n... dimension=3,\n... metric=\"cosine\",\n... ))\n>>> my_async_coll_3a = asyncio.run(my_async_db.get_collection(\n... \"my_already_existing_collection\",\n... ))\n>>> my_async_coll_3b = my_async_db.my_already_existing_collection\n>>> my_async_coll_3c = my_async_db[\"my_already_existing_collection\"]", "references": [ "astrapy.client.DataAPIClient", "astrapy.collection.AsyncCollection" ], "note": "creating an instance of AsyncCollection does not trigger actual creation\nof the collection on the database. The latter should have been created\nbeforehand, e.g. through the `create_collection` method of an AsyncDatabase.", "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.api_options
{ "kind": "attribute", "name": "api_options", "path": "astrapy.collection.AsyncCollection.api_options", "parameters": null, "returns": null, "gathered_types": [ "astrapy.api_options.CollectionAPIOptions" ], "value": "api_options = CollectionAPIOptions()", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.callers
{ "kind": "attribute", "name": "callers", "path": "astrapy.collection.AsyncCollection.callers", "parameters": null, "returns": null, "gathered_types": null, "value": "callers = callers_param", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": null, "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.with_options
Create a clone of this collection with some changed attributes.
{ "kind": "function", "name": "with_options", "path": "astrapy.collection.AsyncCollection.with_options", "parameters": [ { "name": "name", "type": "str | None", "description": "the name of the collection. This parameter is useful to\nquickly spawn AsyncCollection instances each pointing to a different\ncollection existing in the same keyspace.", "default": "None", "value": "None" }, { "name": "embedding_api_key", "type": "str | EmbeddingHeadersProvider | None", "description": "optional API key(s) for interacting with the collection.\nIf an embedding service is configured, and this parameter is not None,\neach Data API call will include the necessary embedding-related headers\nas specified by this parameter. If a string is passed, it translates\ninto the one \"embedding api key\" header\n(i.e. `astrapy.authentication.EmbeddingAPIKeyHeaderProvider`).\nFor some vectorize providers/models, if using header-based authentication,\nspecialized subclasses of `astrapy.authentication.EmbeddingHeadersProvider`\nshould be supplied.", "default": "None", "value": "None" }, { "name": "collection_max_time_ms", "type": "int | None", "description": "a default timeout, in millisecond, for the duration of each\noperation on the collection. Individual timeouts can be provided to\neach collection method call and will take precedence, with this value\nbeing an overall default.\nNote that for some methods involving multiple API calls (such as\n`find`, `delete_many`, `insert_many` and so on), it is strongly suggested\nto provide a specific timeout as the default one likely wouldn't make\nmuch sense.", "default": "None", "value": "None" }, { "name": "callers", "type": "Sequence[CallerType]", "description": "a list of caller identities, i.e. applications, or frameworks,\non behalf of which the Data API calls are performed. These end up\nin the request user-agent.\nEach caller identity is a (\"caller_name\", \"caller_version\") pair.", "default": "[]", "value": "[]" }, { "name": "caller_name", "type": "str | None", "description": "*DEPRECATED*, use `callers`. Removal 2.0. Name of the\napplication, or framework, on behalf of which the Data API calls\nare performed. This ends up in the request user-agent.", "default": "None", "value": "None" }, { "name": "caller_version", "type": "str | None", "description": "version of the caller. *DEPRECATED*, use `callers`.\nRemoval 2.0.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "AsyncCollection", "description": "a new AsyncCollection instance." } ], "gathered_types": [ "astrapy.collection.AsyncCollection", "astrapy.authentication.EmbeddingHeadersProvider", "astrapy.constants.CallerType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_other_async_coll = my_async_coll.with_options(\n... name=\"the_other_coll\",\n... callers=[(\"caller_identity\", \"0.1.2\")],\n... )", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.to_sync
Create a Collection from this one. Save for the arguments explicitly provided as overrides, everything else is kept identical to this collection in the copy (the database is converted into a sync object).
{ "kind": "function", "name": "to_sync", "path": "astrapy.collection.AsyncCollection.to_sync", "parameters": [ { "name": "database", "type": "Database | None", "description": "a Database object, instantiated earlier.\nThis represents the database the new collection belongs to.", "default": "None", "value": "None" }, { "name": "name", "type": "str | None", "description": "the collection name. This parameter should match an existing\ncollection on the database.", "default": "None", "value": "None" }, { "name": "keyspace", "type": "str | None", "description": "this is the keyspace to which the collection belongs.\nIf not specified, the database's working keyspace is used.", "default": "None", "value": "None" }, { "name": "namespace", "type": "str | None", "description": "an alias for `keyspace`. *DEPRECATED*, removal in 2.0.", "default": "None", "value": "None" }, { "name": "embedding_api_key", "type": "str | EmbeddingHeadersProvider | None", "description": "optional API key(s) for interacting with the collection.\nIf an embedding service is configured, and this parameter is not None,\neach Data API call will include the necessary embedding-related headers\nas specified by this parameter. If a string is passed, it translates\ninto the one \"embedding api key\" header\n(i.e. `astrapy.authentication.EmbeddingAPIKeyHeaderProvider`).\nFor some vectorize providers/models, if using header-based authentication,\nspecialized subclasses of `astrapy.authentication.EmbeddingHeadersProvider`\nshould be supplied.", "default": "None", "value": "None" }, { "name": "collection_max_time_ms", "type": "int | None", "description": "a default timeout, in millisecond, for the duration of each\noperation on the collection. Individual timeouts can be provided to\neach collection method call and will take precedence, with this value\nbeing an overall default.\nNote that for some methods involving multiple API calls (such as\n`find`, `delete_many`, `insert_many` and so on), it is strongly suggested\nto provide a specific timeout as the default one likely wouldn't make\nmuch sense.", "default": "None", "value": "None" }, { "name": "callers", "type": "Sequence[CallerType]", "description": "a list of caller identities, i.e. applications, or frameworks,\non behalf of which the Data API calls are performed. These end up\nin the request user-agent.\nEach caller identity is a (\"caller_name\", \"caller_version\") pair.", "default": "[]", "value": "[]" }, { "name": "caller_name", "type": "str | None", "description": "*DEPRECATED*, use `callers`. Removal 2.0. Name of the\napplication, or framework, on behalf of which the Data API calls\nare performed. This ends up in the request user-agent.", "default": "None", "value": "None" }, { "name": "caller_version", "type": "str | None", "description": "version of the caller. *DEPRECATED*, use `callers`.\nRemoval 2.0.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "Collection", "description": "the new copy, a Collection instance." } ], "gathered_types": [ "astrapy.authentication.EmbeddingHeadersProvider", "astrapy.database.Database", "astrapy.constants.CallerType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_async_coll.to_sync().count_documents({}, upper_bound=100)\n77", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.set_caller
Set a new identity for the application/framework on behalf of which the Data API calls are performed (the "caller").
{ "kind": "function", "name": "set_caller", "path": "astrapy.collection.AsyncCollection.set_caller", "parameters": [ { "name": "caller_name", "type": "str | None", "description": "name of the application, or framework, on behalf of which\nthe Data API calls are performed. This ends up in the request user-agent.", "default": "None", "value": "None" }, { "name": "caller_version", "type": "str | None", "description": "version of the caller.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "None", "description": null } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.set_caller(caller_name=\"the_caller\", caller_version=\"0.1.0\")", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.options
Get the collection options, i.e. its configuration as read from the database. The method issues a request to the Data API each time is invoked, without caching mechanisms: this ensures up-to-date information for usages such as real-time collection validation by the application.
{ "kind": "function", "name": "options", "path": "astrapy.collection.AsyncCollection.options", "parameters": [ { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "CollectionOptions", "description": "a CollectionOptions instance describing the collection." }, { "name": null, "type": "CollectionOptions", "description": "(See also the database `list_collections` method.)" } ], "gathered_types": [ "astrapy.info.CollectionOptions" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> asyncio.run(my_async_coll.options())\nCollectionOptions(vector=CollectionVectorOptions(dimension=3, metric='cosine'))", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.info
Information on the collection (name, location, database), in the form of a CollectionInfo object. Not to be confused with the collection `options` method (related to the collection internal configuration).
{ "kind": "function", "name": "info", "path": "astrapy.collection.AsyncCollection.info", "parameters": null, "returns": [ { "name": null, "type": "CollectionInfo", "description": null } ], "gathered_types": [ "astrapy.info.CollectionInfo" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_async_coll.info().database_info.region\n'us-east1'\n>>> my_async_coll.info().full_name\n'default_keyspace.my_v_collection'", "references": null, "note": "the returned CollectionInfo wraps, among other things,\nthe database information: as such, calling this method\ntriggers the same-named method of a Database object (which, in turn,\nperforms a HTTP request to the DevOps API).\nSee the documentation for `Database.info()` for more details.", "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.database
a Database object, the database this collection belongs to.
{ "kind": "attribute", "name": "database", "path": "astrapy.collection.AsyncCollection.database", "parameters": null, "returns": null, "gathered_types": [ "astrapy.database.AsyncDatabase" ], "value": "database: AsyncDatabase", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_async_coll.database.name\n'quicktest'", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.namespace
The namespace this collection is in. *DEPRECATED* (removal in 2.0). Switch to the "keyspace" property.**
{ "kind": "attribute", "name": "namespace", "path": "astrapy.collection.AsyncCollection.namespace", "parameters": null, "returns": null, "gathered_types": null, "value": "namespace: str", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_async_coll.namespace\n'default_keyspace'", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.keyspace
The keyspace this collection is in.
{ "kind": "attribute", "name": "keyspace", "path": "astrapy.collection.AsyncCollection.keyspace", "parameters": null, "returns": null, "gathered_types": null, "value": "keyspace: str", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_coll.keyspace\n'default_keyspace'", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.name
The name of this collection.
{ "kind": "attribute", "name": "name", "path": "astrapy.collection.AsyncCollection.name", "parameters": null, "returns": null, "gathered_types": null, "value": "name: str", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_async_coll.name\n'my_v_collection'", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.full_name
The fully-qualified collection name within the database, in the form "keyspace.collection_name".
{ "kind": "attribute", "name": "full_name", "path": "astrapy.collection.AsyncCollection.full_name", "parameters": null, "returns": null, "gathered_types": null, "value": "full_name: str", "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> my_async_coll.full_name\n'default_keyspace.my_v_collection'", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.insert_one
Insert a single document in the collection in an atomic operation.
{ "kind": "function", "name": "insert_one", "path": "astrapy.collection.AsyncCollection.insert_one", "parameters": [ { "name": "document", "type": "DocumentType", "description": "the dictionary expressing the document to insert.\nThe `_id` field of the document can be left out, in which\ncase it will be created automatically.", "default": null, "value": null }, { "name": "vector", "type": "VectorType | None", "description": "a vector (a list of numbers appropriate for the collection)\nfor the document. Passing this parameter is equivalent to\nproviding a `$vector` field within the document itself,\nhowever the two are mutually exclusive.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the document instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector, if such a service\nis configured for the collection. Passing this parameter is\nequivalent to providing a `$vectorize` field in the document itself,\nhowever the two are mutually exclusive.\nMoreover, this parameter cannot coexist with `vector`.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the document instead.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "InsertOneResult", "description": "an InsertOneResult object." } ], "gathered_types": [ "astrapy.constants.VectorType", "astrapy.constants.DocumentType", "astrapy.results.InsertOneResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> async def write_and_count(acol: AsyncCollection) -> None:\n... count0 = await acol.count_documents({}, upper_bound=10)\n... print(\"count0\", count0)\n... await acol.insert_one(\n... {\n... \"age\": 30,\n... \"name\": \"Smith\",\n... \"food\": [\"pear\", \"peach\"],\n... \"likes_fruit\": True,\n... },\n... )\n... await acol.insert_one({\"_id\": \"user-123\", \"age\": 50, \"name\": \"Maccio\"})\n... count1 = await acol.count_documents({}, upper_bound=10)\n... print(\"count1\", count1)\n...\n>>> asyncio.run(write_and_count(my_async_coll))\ncount0 0\ncount1 2\n\n>>> asyncio.run(my_async_coll.insert_one({\"tag\": v\", \"$vector\": [10, 11]}))\nInsertOneResult(...)", "references": null, "note": "If an `_id` is explicitly provided, which corresponds to a document\nthat exists already in the collection, an error is raised and\nthe insertion fails.", "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.insert_many
Returns: an InsertManyResult object.
{ "kind": "function", "name": "insert_many", "path": "astrapy.collection.AsyncCollection.insert_many", "parameters": [ { "name": "documents", "type": "Iterable[DocumentType]", "description": "an iterable of dictionaries, each a document to insert.\nDocuments may specify their `_id` field or leave it out, in which\ncase it will be added automatically.", "default": null, "value": null }, { "name": "vectors", "type": "Iterable[VectorType | None] | None", "description": "an optional list of vectors (as many vectors as the provided\ndocuments) to associate to the documents when inserting.\nPassing vectors this way is indeed equivalent to the \"$vector\" field\nof the documents, however the two are mutually exclusive.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the documents instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "Iterable[str | None] | None", "description": "an optional list of strings to be made into as many vectors\n(one per document), if such a service is configured for the collection.\nPassing this parameter is equivalent to providing a `$vectorize`\nfield in the documents themselves, however the two are mutually exclusive.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the documents instead.", "default": "None", "value": "None" }, { "name": "ordered", "type": "bool", "description": "if False (default), the insertions can occur in arbitrary order\nand possibly concurrently. If True, they are processed sequentially.\nIf there are no specific reasons against it, unordered insertions are to\nbe preferred as they complete much faster.", "default": "False", "value": "False" }, { "name": "chunk_size", "type": "int | None", "description": "how many documents to include in a single API request.\nExceeding the server maximum allowed value results in an error.\nLeave it unspecified (recommended) to use the system default.", "default": "None", "value": "None" }, { "name": "concurrency", "type": "int | None", "description": "maximum number of concurrent requests to the API at\na given time. It cannot be more than one for ordered insertions.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the operation.\nIf not passed, the collection-level setting is used instead:\nIf many documents are being inserted, this method corresponds\nto several HTTP requests: in such cases one may want to specify\na more tolerant timeout here.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "InsertManyResult", "description": null } ], "gathered_types": [ "astrapy.constants.VectorType", "astrapy.constants.DocumentType", "astrapy.results.InsertManyResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> async def write_and_count(acol: AsyncCollection) -> None:\n... count0 = await acol.count_documents({}, upper_bound=10)\n... print(\"count0\", count0)\n... im_result1 = await acol.insert_many(\n... [\n... {\"a\": 10},\n... {\"a\": 5},\n... {\"b\": [True, False, False]},\n... ],\n... ordered=True,\n... )\n... print(\"inserted1\", im_result1.inserted_ids)\n... count1 = await acol.count_documents({}, upper_bound=100)\n... print(\"count1\", count1)\n... await acol.insert_many(\n... [{\"seq\": i} for i in range(50)],\n... concurrency=5,\n... )\n... count2 = await acol.count_documents({}, upper_bound=100)\n... print(\"count2\", count2)\n...\n>>> asyncio.run(write_and_count(my_async_coll))\ncount0 0\ninserted1 ['e3c2a684-...', '1de4949f-...', '167dacc3-...']\ncount1 3\ncount2 53\n>>> asyncio.run(my_async_coll.insert_many(\n... [\n... {\"tag\": \"a\", \"$vector\": [1, 2]},\n... {\"tag\": \"b\", \"$vector\": [3, 4]},\n... ]\n... ))\nInsertManyResult(...)", "references": null, "note": "A failure mode for this command is related to certain faulty documents\nfound among those to insert: a document may have the an `_id` already\npresent on the collection, or its vector dimension may not\nmatch the collection setting.\n\nFor an ordered insertion, the method will raise an exception at\nthe first such faulty document -- nevertheless, all documents processed\nuntil then will end up being written to the database.\n\nFor unordered insertions, if the error stems from faulty documents\nthe insertion proceeds until exhausting the input documents: then,\nan exception is raised -- and all insertable documents will have been\nwritten to the database, including those \"after\" the troublesome ones.\n\nIf, on the other hand, there are errors not related to individual\ndocuments (such as a network connectivity error), the whole\n`insert_many` operation will stop in mid-way, an exception will be raised,\nand only a certain amount of the input documents will\nhave made their way to the database.", "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.find
Find documents on the collection, matching a certain provided filter. The method returns a Cursor that can then be iterated over. Depending on the method call pattern, the iteration over all documents can reflect collection mutations occurred since the `find` method was called, or not. In cases where the cursor reflects mutations in real-time, it will iterate over cursors in an approximate way (i.e. exhibiting occasional skipped or duplicate documents). This happens when making use of the `sort` option in a non-vector-search manner.
{ "kind": "function", "name": "find", "path": "astrapy.collection.AsyncCollection.find", "parameters": [ { "name": "filter", "type": "FilterType | None", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": "None", "value": "None" }, { "name": "projection", "type": "ProjectionType | None", "description": "it controls which parts of the document are returned.\nIt can be an allow-list: `{\"f1\": True, \"f2\": True}`,\nor a deny-list: `{\"fx\": False, \"fy\": False}`, but not a mixture\n(except for the `_id` and other special fields, which can be\nassociated to both True or False independently of the rest\nof the specification).\nThe special star-projections `{\"*\": True}` and `{\"*\": False}`\nhave the effect of returning the whole document and `{}` respectively.\nFor lists in documents, slice directives can be passed to select\nportions of the list: for instance, `{\"array\": {\"$slice\": 2}}`,\n`{\"array\": {\"$slice\": -2}}`, `{\"array\": {\"$slice\": [4, 2]}}` or\n`{\"array\": {\"$slice\": [-4, 2]}}`.\nAn iterable over strings will be treated implicitly as an allow-list.\nThe default projection (used if this parameter is not passed) does not\nnecessarily include \"special\" fields such as `$vector` or `$vectorize`.\nSee the Data API documentation for more on projections.", "default": "None", "value": "None" }, { "name": "skip", "type": "int | None", "description": "with this integer parameter, what would be the first `skip`\ndocuments returned by the query are discarded, and the results\nstart from the (skip+1)-th document.\nThis parameter can be used only in conjunction with an explicit\n`sort` criterion of the ascending/descending type (i.e. it cannot\nbe used when not sorting, nor with vector-based ANN search).", "default": "None", "value": "None" }, { "name": "limit", "type": "int | None", "description": "this (integer) parameter sets a limit over how many documents\nare returned. Once `limit` is reached (or the cursor is exhausted\nfor lack of matching documents), nothing more is returned.", "default": "None", "value": "None" }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to perform vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search).\nWhen running similarity search on a collection, no other sorting\ncriteria can be specified. Moreover, there is an upper bound\nto the number of documents that can be returned. For details,\nsee the Note about upper bounds and the Data API documentation.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nThis can be supplied in (exclusive) alternative to `vector`,\nprovided such a service is configured for the collection,\nand achieves the same effect.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "include_similarity", "type": "bool | None", "description": "a boolean to request the numeric value of the\nsimilarity to be returned as an added \"$similarity\" key in each\nreturned document. Can only be used for vector ANN search, i.e.\nwhen either `vector` is supplied or the `sort` parameter has the\nshape {\"$vector\": ...}.", "default": "None", "value": "None" }, { "name": "include_sort_vector", "type": "bool | None", "description": "a boolean to request query vector used in this search.\nIf set to True (and if the invocation is a vector search), calling\nthe `get_sort_vector` method on the returned cursor will yield\nthe vector used for the ANN search.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the order\nthe documents are returned. See the Note about sorting, as well as\nthe one about upper bounds, for details.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for each single one\nof the underlying HTTP requests used to fetch documents as the\ncursor is iterated over.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "AsyncCursor", "description": "an AsyncCursor object representing iterations over the matching documents" }, { "name": null, "type": "AsyncCursor", "description": "(see the AsyncCursor object for how to use it. The simplest thing is to" }, { "name": null, "type": "AsyncCursor", "description": "run a for loop: `for document in collection.sort(...):`)." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.VectorType", "astrapy.constants.ProjectionType", "astrapy.cursors.AsyncCursor" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> async def run_finds(acol: AsyncCollection) -> None:\n... filter = {\"seq\": {\"$exists\": True}}\n... print(\"find results 1:\")\n... async for doc in acol.find(filter, projection={\"seq\": True}, limit=5):\n... print(doc[\"seq\"])\n... async_cursor1 = acol.find(\n... {},\n... limit=4,\n... sort={\"seq\": astrapy.constants.SortDocuments.DESCENDING},\n... )\n... ids = [doc[\"_id\"] async for doc in async_cursor1]\n... print(\"find results 2:\", ids)\n... async_cursor2 = acol.find({}, limit=3)\n... seqs = await async_cursor2.distinct(\"seq\")\n... print(\"distinct results 3:\", seqs)\n...\n>>> asyncio.run(run_finds(my_async_coll))\nfind results 1:\n48\n35\n7\n11\n13\nfind results 2: ['d656cd9d-...', '479c7ce8-...', '96dc87fd-...', '83f0a21f-...']\ndistinct results 3: [48, 35, 7]/n/n/n>>> async def run_vector_finds(acol: AsyncCollection) -> None:\n... await acol.insert_many([\n... {\"tag\": \"A\", \"$vector\": [4, 5]},\n... {\"tag\": \"B\", \"$vector\": [3, 4]},\n... {\"tag\": \"C\", \"$vector\": [3, 2]},\n... {\"tag\": \"D\", \"$vector\": [4, 1]},\n... {\"tag\": \"E\", \"$vector\": [2, 5]},\n... ])\n... ann_tags = [\n... document[\"tag\"]\n... async for document in acol.find(\n... {},\n... sort={\"$vector\": [3, 3]},\n... limit=3,\n... )\n... ]\n... return ann_tags\n...\n>>> asyncio.run(run_vector_finds(my_async_coll))\n['A', 'B', 'C']\n>>> # (assuming the collection has metric VectorMetric.COSINE)/n/n/n>>> async_cursor = my_async_coll.find(\n... sort={\"$vector\": [3, 3]},\n... limit=3,\n... include_sort_vector=True,\n... )\n>>> asyncio.run(async_cursor.get_sort_vector())\n[3.0, 3.0]\n>>> asyncio.run(async_cursor.__anext__())\n{'_id': 'b13ce177-738e-47ec-bce1-77738ee7ec93', 'tag': 'A'}\n>>> asyncio.run(async_cursor.get_sort_vector())\n[3.0, 3.0]", "references": null, "note": "When not specifying sorting criteria at all (by vector or otherwise),\nthe cursor can scroll through an arbitrary number of documents as\nthe Data API and the client periodically exchange new chunks of documents.\nIt should be noted that the behavior of the cursor in the case documents\nhave been added/removed after the `find` was started depends on database\ninternals and it is not guaranteed, nor excluded, that such \"real-time\"\nchanges in the data would be picked up by the cursor.", "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.find_one
Run a search, returning the first document in the collection that matches provided filters, if any is found.
{ "kind": "function", "name": "find_one", "path": "astrapy.collection.AsyncCollection.find_one", "parameters": [ { "name": "filter", "type": "FilterType | None", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": "None", "value": "None" }, { "name": "projection", "type": "ProjectionType | None", "description": "it controls which parts of the document are returned.\nIt can be an allow-list: `{\"f1\": True, \"f2\": True}`,\nor a deny-list: `{\"fx\": False, \"fy\": False}`, but not a mixture\n(except for the `_id` and other special fields, which can be\nassociated to both True or False independently of the rest\nof the specification).\nThe special star-projections `{\"*\": True}` and `{\"*\": False}`\nhave the effect of returning the whole document and `{}` respectively.\nFor lists in documents, slice directives can be passed to select\nportions of the list: for instance, `{\"array\": {\"$slice\": 2}}`,\n`{\"array\": {\"$slice\": -2}}`, `{\"array\": {\"$slice\": [4, 2]}}` or\n`{\"array\": {\"$slice\": [-4, 2]}}`.\nAn iterable over strings will be treated implicitly as an allow-list.\nThe default projection (used if this parameter is not passed) does not\nnecessarily include \"special\" fields such as `$vector` or `$vectorize`.\nSee the Data API documentation for more on projections.", "default": "None", "value": "None" }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to perform vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), extracting the most\nsimilar document in the collection matching the filter.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nUsing vectorize assumes a suitable service is configured for the collection.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "include_similarity", "type": "bool | None", "description": "a boolean to request the numeric value of the\nsimilarity to be returned as an added \"$similarity\" key in the\nreturned document. Can only be used for vector ANN search, i.e.\nwhen either `vector` is supplied or the `sort` parameter has the\nshape {\"$vector\": ...}.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the order\nthe documents are returned. See the Note about sorting for details.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "DocumentType | None", "description": "a dictionary expressing the required document, otherwise None." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.DocumentType", "astrapy.constants.VectorType", "astrapy.constants.ProjectionType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> async def demo_find_one(acol: AsyncCollection) -> None:\n.... print(\"Count:\", await acol.count_documents({}, upper_bound=100))\n... result0 = await acol.find_one({})\n... print(\"result0\", result0)\n... result1 = await acol.find_one({\"seq\": 10})\n... print(\"result1\", result1)\n... result2 = await acol.find_one({\"seq\": 1011})\n... print(\"result2\", result2)\n... result3 = await acol.find_one({}, projection={\"seq\": False})\n... print(\"result3\", result3)\n... result4 = await acol.find_one(\n... {},\n... sort={\"seq\": astrapy.constants.SortDocuments.DESCENDING},\n... )\n... print(\"result4\", result4)\n...\n>>>\n>>> asyncio.run(demo_find_one(my_async_coll))\nCount: 50\nresult0 {'_id': '479c7ce8-...', 'seq': 48}\nresult1 {'_id': '93e992c4-...', 'seq': 10}\nresult2 None\nresult3 {'_id': '479c7ce8-...'}\nresult4 {'_id': 'd656cd9d-...', 'seq': 49}\n\n>>> asyncio.run(my_async_coll.find_one(\n... {},\n... sort={\"$vector\": [1, 0]},\n... projection={\"*\": True},\n... ))\n{'_id': '...', 'tag': 'D', '$vector': [4.0, 1.0]}", "references": null, "note": "See the `find` method for more details on the accepted parameters\n(whereas `skip` and `limit` are not valid parameters for `find_one`).", "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.distinct
Return a list of the unique values of `key` across the documents in the collection that match the provided filter.
{ "kind": "function", "name": "distinct", "path": "astrapy.collection.AsyncCollection.distinct", "parameters": [ { "name": "key", "type": "str", "description": "the name of the field whose value is inspected across documents.\nKeys can use dot-notation to descend to deeper document levels.\nExample of acceptable `key` values:\n \"field\"\n \"field.subfield\"\n \"field.3\"\n \"field.3.subfield\"\nIf lists are encountered and no numeric index is specified,\nall items in the list are visited.", "default": null, "value": null }, { "name": "filter", "type": "FilterType | None", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": "None", "value": "None" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, with the same meaning as for `find`.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "list[Any]", "description": "a list of all different values for `key` found across the documents" }, { "name": null, "type": "list[Any]", "description": "that match the filter. The result list has no repeated items." } ], "gathered_types": [ "astrapy.constants.FilterType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> async def run_distinct(acol: AsyncCollection) -> None:\n... await acol.insert_many(\n... [\n... {\"name\": \"Marco\", \"food\": [\"apple\", \"orange\"], \"city\": \"Helsinki\"},\n... {\"name\": \"Emma\", \"food\": {\"likes_fruit\": True, \"allergies\": []}},\n... ]\n... )\n... distinct0 = await acol.distinct(\"name\")\n... print(\"distinct('name')\", distinct0)\n... distinct1 = await acol.distinct(\"city\")\n... print(\"distinct('city')\", distinct1)\n... distinct2 = await acol.distinct(\"food\")\n... print(\"distinct('food')\", distinct2)\n... distinct3 = await acol.distinct(\"food.1\")\n... print(\"distinct('food.1')\", distinct3)\n... distinct4 = await acol.distinct(\"food.allergies\")\n... print(\"distinct('food.allergies')\", distinct4)\n... distinct5 = await acol.distinct(\"food.likes_fruit\")\n... print(\"distinct('food.likes_fruit')\", distinct5)\n...\n>>> asyncio.run(run_distinct(my_async_coll))\ndistinct('name') ['Emma', 'Marco']\ndistinct('city') ['Helsinki']\ndistinct('food') [{'likes_fruit': True, 'allergies': []}, 'apple', 'orange']\ndistinct('food.1') ['orange']\ndistinct('food.allergies') []\ndistinct('food.likes_fruit') [True]", "references": null, "note": "For details on the behaviour of \"distinct\" in conjunction with\nreal-time changes in the collection contents, see the\nNote of the `find` command.", "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.count_documents
Count the documents in the collection matching the specified filter.
{ "kind": "function", "name": "count_documents", "path": "astrapy.collection.AsyncCollection.count_documents", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "upper_bound", "type": "int", "description": "a required ceiling on the result of the count operation.\nIf the actual number of documents exceeds this value,\nan exception will be raised.\nFurthermore, if the actual number of documents exceeds the maximum\ncount that the Data API can reach (regardless of upper_bound),\nan exception will be raised.", "default": null, "value": null }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "int", "description": "the exact count of matching documents." } ], "gathered_types": [ "astrapy.constants.FilterType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> async def do_count_docs(acol: AsyncCollection) -> None:\n... await acol.insert_many([{\"seq\": i} for i in range(20)])\n... count0 = await acol.count_documents({}, upper_bound=100)\n... print(\"count0\", count0)\n... count1 = await acol.count_documents({\"seq\":{\"$gt\": 15}}, upper_bound=100)\n... print(\"count1\", count1)\n... count2 = await acol.count_documents({}, upper_bound=10)\n... print(\"count2\", count2)\n...\n>>> asyncio.run(do_count_docs(my_async_coll))\ncount0 20\ncount1 4\nTraceback (most recent call last):\n ... ...\nastrapy.exceptions.TooManyDocumentsToCountException", "references": null, "note": "Count operations are expensive: for this reason, the best practice\nis to provide a reasonable `upper_bound` according to the caller\nexpectations. Moreover, indiscriminate usage of count operations\nfor sizeable amounts of documents (i.e. in the thousands and more)\nis discouraged in favor of alternative application-specific solutions.\nKeep in mind that the Data API has a hard upper limit on the amount\nof documents it will count, and that an exception will be thrown\nby this method if this limit is encountered.", "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.estimated_document_count
Query the API server for an estimate of the document count in the collection. Contrary to `count_documents`, this method has no filtering parameters.
{ "kind": "function", "name": "estimated_document_count", "path": "astrapy.collection.AsyncCollection.estimated_document_count", "parameters": [ { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "int", "description": "a server-provided estimate count of the documents in the collection." } ], "gathered_types": null, "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> asyncio.run(my_async_coll.estimated_document_count())\n35700", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.find_one_and_replace
Find a document on the collection and replace it entirely with a new one, optionally inserting a new one if no match is found. Args: filter: a predicate expressed as a dictionary according to the Data API filter syntax. Examples are: {} {"name": "John"} {"price": {"$lt": 100}} {"$and": [{"name": "John"}, {"price": {"$lt": 100}}]} See the Data API documentation for the full set of operators. replacement: the new document to write into the collection. projection: it controls which parts of the document are returned. It can be an allow-list: `{"f1": True, "f2": True}`, or a deny-list: `{"fx": False, "fy": False}`, but not a mixture (except for the `_id` and other special fields, which can be associated to both True or False independently of the rest of the specification). The special star-projections `{"*": True}` and `{"*": False}` have the effect of returning the whole document and `{}` respectively. For lists in documents, slice directives can be passed to select portions of the list: for instance, `{"array": {"$slice": 2}}`, `{"array": {"$slice": -2}}`, `{"array": {"$slice": [4, 2]}}` or `{"array": {"$slice": [-4, 2]}}`. An iterable over strings will be treated implicitly as an allow-list. The default projection (used if this parameter is not passed) does not necessarily include "special" fields such as `$vector` or `$vectorize`. See the Data API documentation for more on projections. vector: a suitable vector, i.e. a list of float numbers of the appropriate dimensionality, to use vector search (i.e. ANN, or "approximate nearest-neighbours" search), as the sorting criterion. In this way, the matched document (if any) will be the one that is most similar to the provided vector. *DEPRECATED* (removal in 2.0). Use a `$vector` key in the sort clause dict instead. vectorize: a string to be made into a vector to perform vector search. Using vectorize assumes a suitable service is configured for the collection. *DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the sort clause dict instead. sort: with this dictionary parameter one can control the sorting order of the documents matching the filter, effectively determining what document will come first and hence be the replaced one. See the `find` method for more on sorting. Vector-based ANN sorting is achieved by providing a "$vector" or a "$vectorize" key in `sort`. upsert: this parameter controls the behavior in absence of matches. If True, `replacement` is inserted as a new document if no matches are found on the collection. If False, the operation silently does nothing in case of no matches. return_document: a flag controlling what document is returned: if set to `ReturnDocument.BEFORE`, or the string "before", the document found on database is returned; if set to `ReturnDocument.AFTER`, or the string "after", the new document is returned. The default is "before". max_time_ms: a timeout, in milliseconds, for the underlying HTTP request. If not passed, the collection-level setting is used instead.
{ "kind": "function", "name": "find_one_and_replace", "path": "astrapy.collection.AsyncCollection.find_one_and_replace", "parameters": [ { "name": "filter", "type": "FilterType", "description": null, "default": null, "value": null }, { "name": "replacement", "type": "DocumentType", "description": null, "default": null, "value": null }, { "name": "projection", "type": "ProjectionType | None", "description": null, "default": "None", "value": null }, { "name": "vector", "type": "VectorType | None", "description": null, "default": "None", "value": null }, { "name": "vectorize", "type": "str | None", "description": null, "default": "None", "value": null }, { "name": "sort", "type": "SortType | None", "description": null, "default": "None", "value": null }, { "name": "upsert", "type": "bool", "description": null, "default": "False", "value": null }, { "name": "return_document", "type": "str", "description": null, "default": "ReturnDocument.BEFORE", "value": null }, { "name": "max_time_ms", "type": "int | None", "description": null, "default": "None", "value": null } ], "returns": [ { "name": null, "type": "DocumentType | None", "description": "A document, either the one before the replace operation or the" }, { "name": null, "type": "DocumentType | None", "description": "one after that. Alternatively, the method returns None to represent" }, { "name": null, "type": "DocumentType | None", "description": "that no matching document was found, or that no replacement" }, { "name": null, "type": "DocumentType | None", "description": "was inserted (depending on the `return_document` parameter)." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.ReturnDocument", "astrapy.constants.DocumentType", "astrapy.constants.VectorType", "BEFORE", "astrapy.constants.ProjectionType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> async def do_find_one_and_replace(acol: AsyncCollection) -> None:\n... await acol.insert_one({\"_id\": \"rule1\", \"text\": \"all animals are equal\"})\n... result0 = await acol.find_one_and_replace(\n... {\"_id\": \"rule1\"},\n... {\"text\": \"some animals are more equal!\"},\n... )\n... print(\"result0\", result0)\n... result1 = await acol.find_one_and_replace(\n... {\"text\": \"some animals are more equal!\"},\n... {\"text\": \"and the pigs are the rulers\"},\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... )\n... print(\"result1\", result1)\n... result2 = await acol.find_one_and_replace(\n... {\"_id\": \"rule2\"},\n... {\"text\": \"F=ma^2\"},\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... )\n... print(\"result2\", result2)\n... result3 = await acol.find_one_and_replace(\n... {\"_id\": \"rule2\"},\n... {\"text\": \"F=ma\"},\n... upsert=True,\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... projection={\"_id\": False},\n... )\n... print(\"result3\", result3)\n...\n>>> asyncio.run(do_find_one_and_replace(my_async_coll))\nresult0 {'_id': 'rule1', 'text': 'all animals are equal'}\nresult1 {'_id': 'rule1', 'text': 'and the pigs are the rulers'}\nresult2 None\nresult3 {'text': 'F=ma'}", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.replace_one
Replace a single document on the collection with a new one, optionally inserting a new one if no match is found.
{ "kind": "function", "name": "replace_one", "path": "astrapy.collection.AsyncCollection.replace_one", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "replacement", "type": "DocumentType", "description": "the new document to write into the collection.", "default": null, "value": null }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to use vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), as the sorting criterion.\nIn this way, the matched document (if any) will be the one\nthat is most similar to the provided vector.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nUsing vectorize assumes a suitable service is configured for the collection.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the sorting\norder of the documents matching the filter, effectively\ndetermining what document will come first and hence be the\nreplaced one. See the `find` method for more on sorting.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "upsert", "type": "bool", "description": "this parameter controls the behavior in absence of matches.\nIf True, `replacement` is inserted as a new document\nif no matches are found on the collection. If False,\nthe operation silently does nothing in case of no matches.", "default": "False", "value": "False" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "UpdateResult", "description": "an UpdateResult object summarizing the outcome of the replace operation." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.DocumentType", "astrapy.results.UpdateResult", "astrapy.constants.VectorType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> async def do_replace_one(acol: AsyncCollection) -> None:\n... await acol.insert_one({\"Marco\": \"Polo\"})\n... result0 = await acol.replace_one(\n... {\"Marco\": {\"$exists\": True}},\n... {\"Buda\": \"Pest\"},\n... )\n... print(\"result0.update_info\", result0.update_info)\n... doc1 = await acol.find_one({\"Buda\": \"Pest\"})\n... print(\"doc1\", doc1)\n... result1 = await acol.replace_one(\n... {\"Mirco\": {\"$exists\": True}},\n... {\"Oh\": \"yeah?\"},\n... )\n... print(\"result1.update_info\", result1.update_info)\n... result2 = await acol.replace_one(\n... {\"Mirco\": {\"$exists\": True}},\n... {\"Oh\": \"yeah?\"},\n... upsert=True,\n... )\n... print(\"result2.update_info\", result2.update_info)\n...\n>>> asyncio.run(do_replace_one(my_async_coll))\nresult0.update_info {'n': 1, 'updatedExisting': True, 'ok': 1.0, 'nModified': 1}\ndoc1 {'_id': '6e669a5a-...', 'Buda': 'Pest'}\nresult1.update_info {'n': 0, 'updatedExisting': False, 'ok': 1.0, 'nModified': 0}\nresult2.update_info {'n': 1, 'updatedExisting': False, 'ok': 1.0, 'nModified': 0, 'upserted': '30e34e00-...'}", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.find_one_and_update
Find a document on the collection and update it as requested, optionally inserting a new one if no match is found.
{ "kind": "function", "name": "find_one_and_update", "path": "astrapy.collection.AsyncCollection.find_one_and_update", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "update", "type": "dict[str, Any]", "description": "the update prescription to apply to the document, expressed\nas a dictionary as per Data API syntax. Examples are:\n {\"$set\": {\"field\": \"value}}\n {\"$inc\": {\"counter\": 10}}\n {\"$unset\": {\"field\": \"\"}}\nSee the Data API documentation for the full syntax.", "default": null, "value": null }, { "name": "projection", "type": "ProjectionType | None", "description": "it controls which parts of the document are returned.\nIt can be an allow-list: `{\"f1\": True, \"f2\": True}`,\nor a deny-list: `{\"fx\": False, \"fy\": False}`, but not a mixture\n(except for the `_id` and other special fields, which can be\nassociated to both True or False independently of the rest\nof the specification).\nThe special star-projections `{\"*\": True}` and `{\"*\": False}`\nhave the effect of returning the whole document and `{}` respectively.\nFor lists in documents, slice directives can be passed to select\nportions of the list: for instance, `{\"array\": {\"$slice\": 2}}`,\n`{\"array\": {\"$slice\": -2}}`, `{\"array\": {\"$slice\": [4, 2]}}` or\n`{\"array\": {\"$slice\": [-4, 2]}}`.\nAn iterable over strings will be treated implicitly as an allow-list.\nThe default projection (used if this parameter is not passed) does not\nnecessarily include \"special\" fields such as `$vector` or `$vectorize`.\nSee the Data API documentation for more on projections.", "default": "None", "value": "None" }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to use vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), as the sorting criterion.\nIn this way, the matched document (if any) will be the one\nthat is most similar to the provided vector.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nUsing vectorize assumes a suitable service is configured for the collection.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the sorting\norder of the documents matching the filter, effectively\ndetermining what document will come first and hence be the\nreplaced one. See the `find` method for more on sorting.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "upsert", "type": "bool", "description": "this parameter controls the behavior in absence of matches.\nIf True, a new document (resulting from applying the `update`\nto an empty document) is inserted if no matches are found on\nthe collection. If False, the operation silently does nothing\nin case of no matches.", "default": "False", "value": "False" }, { "name": "return_document", "type": "str", "description": "a flag controlling what document is returned:\nif set to `ReturnDocument.BEFORE`, or the string \"before\",\nthe document found on database is returned; if set to\n`ReturnDocument.AFTER`, or the string \"after\", the new\ndocument is returned. The default is \"before\".", "default": "ReturnDocument.BEFORE", "value": "ReturnDocument.BEFORE" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "DocumentType | None", "description": "A document (or a projection thereof, as required), either the one" }, { "name": null, "type": "DocumentType | None", "description": "before the replace operation or the one after that." }, { "name": null, "type": "DocumentType | None", "description": "Alternatively, the method returns None to represent" }, { "name": null, "type": "DocumentType | None", "description": "that no matching document was found, or that no update" }, { "name": null, "type": "DocumentType | None", "description": "was applied (depending on the `return_document` parameter)." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.ReturnDocument", "astrapy.constants.DocumentType", "astrapy.constants.VectorType", "BEFORE", "astrapy.constants.ProjectionType" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> async def do_find_one_and_update(acol: AsyncCollection) -> None:\n... await acol.insert_one({\"Marco\": \"Polo\"})\n... result0 = await acol.find_one_and_update(\n... {\"Marco\": {\"$exists\": True}},\n... {\"$set\": {\"title\": \"Mr.\"}},\n... )\n... print(\"result0\", result0)\n... result1 = await acol.find_one_and_update(\n... {\"title\": \"Mr.\"},\n... {\"$inc\": {\"rank\": 3}},\n... projection=[\"title\", \"rank\"],\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... )\n... print(\"result1\", result1)\n... result2 = await acol.find_one_and_update(\n... {\"name\": \"Johnny\"},\n... {\"$set\": {\"rank\": 0}},\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... )\n... print(\"result2\", result2)\n... result3 = await acol.find_one_and_update(\n... {\"name\": \"Johnny\"},\n... {\"$set\": {\"rank\": 0}},\n... upsert=True,\n... return_document=astrapy.constants.ReturnDocument.AFTER,\n... )\n... print(\"result3\", result3)\n...\n>>> asyncio.run(do_find_one_and_update(my_async_coll))\nresult0 {'_id': 'f7c936d3-b0a0-45eb-a676-e2829662a57c', 'Marco': 'Polo'}\nresult1 {'_id': 'f7c936d3-b0a0-45eb-a676-e2829662a57c', 'title': 'Mr.', 'rank': 3}\nresult2 None\nresult3 {'_id': 'db3d678d-14d4-4caa-82d2-d5fb77dab7ec', 'name': 'Johnny', 'rank': 0}", "references": null, "note": null, "implemented_by": null, "attributes": null }
astrapy.collection.AsyncCollection.update_one
Update a single document on the collection as requested, optionally inserting a new one if no match is found.
{ "kind": "function", "name": "update_one", "path": "astrapy.collection.AsyncCollection.update_one", "parameters": [ { "name": "filter", "type": "FilterType", "description": "a predicate expressed as a dictionary according to the\nData API filter syntax. Examples are:\n {}\n {\"name\": \"John\"}\n {\"price\": {\"$lt\": 100}}\n {\"$and\": [{\"name\": \"John\"}, {\"price\": {\"$lt\": 100}}]}\nSee the Data API documentation for the full set of operators.", "default": null, "value": null }, { "name": "update", "type": "dict[str, Any]", "description": "the update prescription to apply to the document, expressed\nas a dictionary as per Data API syntax. Examples are:\n {\"$set\": {\"field\": \"value}}\n {\"$inc\": {\"counter\": 10}}\n {\"$unset\": {\"field\": \"\"}}\nSee the Data API documentation for the full syntax.", "default": null, "value": null }, { "name": "vector", "type": "VectorType | None", "description": "a suitable vector, i.e. a list of float numbers of the appropriate\ndimensionality, to use vector search (i.e. ANN,\nor \"approximate nearest-neighbours\" search), as the sorting criterion.\nIn this way, the matched document (if any) will be the one\nthat is most similar to the provided vector.\n*DEPRECATED* (removal in 2.0). Use a `$vector` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "vectorize", "type": "str | None", "description": "a string to be made into a vector to perform vector search.\nUsing vectorize assumes a suitable service is configured for the collection.\n*DEPRECATED* (removal in 2.0). Use a `$vectorize` key in the\nsort clause dict instead.", "default": "None", "value": "None" }, { "name": "sort", "type": "SortType | None", "description": "with this dictionary parameter one can control the sorting\norder of the documents matching the filter, effectively\ndetermining what document will come first and hence be the\nreplaced one. See the `find` method for more on sorting.\nVector-based ANN sorting is achieved by providing a \"$vector\"\nor a \"$vectorize\" key in `sort`.", "default": "None", "value": "None" }, { "name": "upsert", "type": "bool", "description": "this parameter controls the behavior in absence of matches.\nIf True, a new document (resulting from applying the `update`\nto an empty document) is inserted if no matches are found on\nthe collection. If False, the operation silently does nothing\nin case of no matches.", "default": "False", "value": "False" }, { "name": "max_time_ms", "type": "int | None", "description": "a timeout, in milliseconds, for the underlying HTTP request.\nIf not passed, the collection-level setting is used instead.", "default": "None", "value": "None" } ], "returns": [ { "name": null, "type": "UpdateResult", "description": "an UpdateResult object summarizing the outcome of the update operation." } ], "gathered_types": [ "astrapy.constants.FilterType", "astrapy.constants.SortType", "astrapy.constants.VectorType", "astrapy.results.UpdateResult" ], "value": null, "yields": null, "imports": null, "properties": null, "bases": null, "exports": null, "example": ">>> async def do_update_one(acol: AsyncCollection) -> None:\n... await acol.insert_one({\"Marco\": \"Polo\"})\n... result0 = await acol.update_one(\n... {\"Marco\": {\"$exists\": True}},\n... {\"$inc\": {\"rank\": 3}},\n... )\n... print(\"result0.update_info\", result0.update_info)\n... result1 = await acol.update_one(\n... {\"Mirko\": {\"$exists\": True}},\n... {\"$inc\": {\"rank\": 3}},\n... )\n... print(\"result1.update_info\", result1.update_info)\n... result2 = await acol.update_one(\n... {\"Mirko\": {\"$exists\": True}},\n... {\"$inc\": {\"rank\": 3}},\n... upsert=True,\n... )\n... print(\"result2.update_info\", result2.update_info)\n...\n>>> asyncio.run(do_update_one(my_async_coll))\nresult0.update_info {'n': 1, 'updatedExisting': True, 'ok': 1.0, 'nModified': 1})\nresult1.update_info {'n': 0, 'updatedExisting': False, 'ok': 1.0, 'nModified': 0})\nresult2.update_info {'n': 1, 'updatedExisting': False, 'ok': 1.0, 'nModified': 0, 'upserted': '75748092-...'}", "references": null, "note": null, "implemented_by": null, "attributes": null }