async def get_schema(self, index: Union[SchemaKey, int, str]) -> str:
LOGGER.debug('<STR_LIT>', index)<EOL>rv_json = json.dumps({})<EOL>with SCHEMA_CACHE.lock:<EOL><INDENT>if SCHEMA_CACHE.contains(index):<EOL><INDENT>LOGGER.info('<STR_LIT>', index)<EOL>rv_json = SCHEMA_CACHE[index]<EOL>LOGGER.debug('<STR_LIT>', rv_json)<EOL>return json.dumps(rv_json)<EOL><DEDENT>if isinstance(index, SchemaKey) or (isinstance(index, str) and '<STR_LIT>' in index):<EOL><INDENT>s_id = schema_id(*index) if isinstance(index, SchemaKey) else index<EOL>s_key = schema_key(s_id)<EOL>req_json = await ledger.build_get_schema_request(self.did, s_id)<EOL>resp_json = await self._submit(req_json)<EOL>resp = json.loads(resp_json)<EOL>if not ('<STR_LIT:result>' in resp and resp['<STR_LIT:result>'].get('<STR_LIT:data>', {}).get('<STR_LIT>', None)):<EOL><INDENT>LOGGER.debug('<STR_LIT>', index)<EOL>raise AbsentSchema('<STR_LIT>'.format(index))<EOL><DEDENT>try:<EOL><INDENT>(_, rv_json) = await ledger.parse_get_schema_response(resp_json)<EOL><DEDENT>except IndyError:  <EOL><INDENT>LOGGER.debug('<STR_LIT>', index)<EOL>raise AbsentSchema('<STR_LIT>'.format(index))<EOL><DEDENT>SCHEMA_CACHE[s_key] = json.loads(rv_json)  <EOL>LOGGER.info('<STR_LIT>', index)<EOL><DEDENT>elif isinstance(index, (int, str)):  <EOL><INDENT>txn_json = await self.get_txn(int(index))<EOL>txn = json.loads(txn_json)<EOL>if txn.get('<STR_LIT:type>', None) == '<STR_LIT>':  <EOL><INDENT>rv_json = await self.get_schema(SchemaKey(<EOL>txn['<STR_LIT>']['<STR_LIT>'],<EOL>txn['<STR_LIT:data>']['<STR_LIT:data>']['<STR_LIT:name>'],<EOL>txn['<STR_LIT:data>']['<STR_LIT:data>']['<STR_LIT:version>']))<EOL><DEDENT>else:<EOL><INDENT>LOGGER.info('<STR_LIT>', index)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>LOGGER.debug('<STR_LIT>')<EOL>raise AbsentSchema('<STR_LIT>'.format(<EOL>type(index),<EOL>index))<EOL><DEDENT><DEDENT>LOGGER.debug('<STR_LIT>', rv_json)<EOL>return rv_json<EOL>
Get schema from ledger by SchemaKey namedtuple (origin DID, name, version),
sequence number, or schema identifier.

Raise AbsentSchema for no such schema, logging any error condition and raising
BadLedgerTxn on bad request.

Retrieve the schema from the agent's schema cache if it has it; cache it
en passant if it does not (and there is a corresponding schema on the ledger).

:param index: schema key (origin DID, name, version), sequence number, or schema identifier
:return: schema json, parsed from ledger