amieclient API

The main client itself

To communicate with the AMIE REST API, create a client object. You’ll need to provide your site name and your API key.

class amieclient.client.AMIEClient(site_name, api_key, amie_url='https://amieclient.xsede.org/v0.10/')

AMIE Client.

Parameters
  • site_name (str) – Name of the client site.

  • api_key (str) – API key secret

  • amie_url (str) – Base URL for the XSEDE AMIE api

Examples

>>> psc_client = amieclient.AMIEClient(site_name='PSC', api_key=some_secrets_store['amie_api_key'])

You can also override the amie_url and usage_url parameters, if you’re doing local development or testing out a new version.

>>> psc_alt_base_client = amieclient.AMIEClient(site_name='PSC', api_key='test_api_key', amie_url='https://amieclient.xsede.org/v0.20_beta/)
clear_packet_client_json(packet_or_id)

Clears the client JSON on the server of the packet corresponding to the given packet_or_id.

See the Swagger documentation for more details.

Parameters

packet_or_id (Packet, int) – The packet or packet_rec_id to clear client_json on.

clear_packet_client_state(packet_or_id)

Clears the client state on the server of the packet corresponding to the given packet_or_id.

See the Swagger documentation for more details.

Parameters

packet_or_id (Packet, int) – The packet or packet_rec_id to clear client_state on.

get_packet(packet_rec_id)

Given a single packet record id, fetches the packet.

See the Swagger documentation for more details.

Parameters

packet_rec_id – The transaction record ID.

Returns

amieclient.Packet

get_transaction(transaction_or_id)

Given a single transaction record id, fetches the related transaction.

See the Swagger documentation for more details.

Parameters

transaction_or_id – The transaction or transaction record ID.

Returns

amieclient.Transaction

list_packets(*, trans_rec_ids=None, outgoing=None, update_time_start=None, update_time_until=None, states=None, client_states=None, transaction_states=None, incoming=None)

Fetches a list of packets based on the provided search parameters

See the Swagger documentation for more details.

Parameters
  • trans_rec_ids (list) – Searches for packets with these transaction record IDs.

  • states (list) – Searches for packets with the provided states.

  • update_time_start (datetime.Datetime) – Searches for packets updated since this time.

  • update_time_until (datetime.Datetime) – Searches for packets updated before this time.

  • states – Searches for packets in the provided states.

  • client_states (list) – Searches for packets in the provided client states.

  • transaction_states (list) – Searches for packets in the provided client states.

  • incoming (bool) – If true, search is limited to incoming packets.

Returns

a list of packets matching the provided parameters.

Return type

amieclient.PacketList

send_packet(packet, skip_validation=False)

Send a packet

See the Swagger documentation for more details.

Parameters

packet (amieclient.Packet) – The packet to send.

Returns

The response from the AMIE API.

Return type

requests.Response

set_packet_client_json(packet_or_id, client_json)

Set the client JSON on the server of the packet corresponding to the given packet_or_id.

See the Swagger documentation for more details.

Parameters
  • packet_or_id (Packet, int) – The packet or packet_rec_id to set client_json on.

  • client_json – The json to set. Can be any serializable object or a string of JSON.

set_packet_client_state(packet_or_id, state)

Set the client state on the server of the packet corresponding to the given packet_or_id.

See the Swagger documentation for more details.

Parameters
  • packet_or_id (Packet, int) – The packet or packet_rec_id to set state on.

  • state (str) – The state to set

set_transaction_failed(transaction_or_id)

Given a single transaction or transaction record id, marks it faield.

See the Swagger documentation for more details.

Parameters

transaction_or_id – The transaction or transaction record ID.

Packets

The REST version of AMIE focuses more on individual packets more than transactions. The amieclient library has a generic Packet class, but in general, as a user of the library, you’ll be using the specific child classes for creating and handling packets.

If you need it, the parent Packet class has an internal classmethod, _find_packet_type, that takes the AMIE name of a packet and returns the corresponding amieclient packet class.

class amieclient.packet.base.Packet(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)

Generic AMIE packet base class

Class parameters:

_packet_type: the type of the packet (string) _expected_reply: expected reply types (list[string] or list[Packet type]) _data_keys_required: Data keys that are required for this packet type _data_keys_not_required_in_reply: Data keys that are required but

whose value can be inferred if this is a reply packet

_data_keys_allowed: Data keys that are allowed for this packet type

Parameters
  • packet_rec_id (str) – The ID for this packet

  • packet_timestamp (datetime.Datetime or str) – A datetime object or str for this packet’s timestamp.

  • additional_data (dict) – Body data that is outsite the AMIE spec.

  • in_reply_to (str, int, amieclient.Packet) – The packet this packet is in response to. Can take a packet, int, string, or None.

as_dict()

This packet, as a dictionary.

classmethod from_dict(data)

Generates an instance of an AMIE packet of this type from provided dictionary

Parameters

data (dict) – Packet data

classmethod from_json(json_string)

Generates an instance of an AMIE packet of this type from provided JSON. Basically just a wrapper around from_dict.

Parameters

json_string (string) – JSON data

json(**json_kwargs)

The JSON representation of this AMIE packet

missing_attributes()

Returns a list of attributes that need to be filled out by the user in order for this packet to be valid.

property packet_type

The AMIE name for this packet type.

pretty_print()

prints() a pretty version of the JSON of this packet

reply_packet(packet_rec_id=None, packet_type=None, force=False)

Returns a packet that the current packet would expect as a response, with the in_reply_to attribute set to the current packet’s ID.

Generally, most packets only have one kind of expected reply, so you should be fine to use reply_packet with just the desired packet_rec_id

Parameters
  • packet_rec_id – The ID of the reply packet, if needed

  • packet_type – Optionally, the type of the reply packet

  • force – will create a reply packet whether or not packet_type is in _expected_reply

Example

>>> my_npc = received_rpc.reply_packet()
reply_with_failure(detail_code='2', message='fail transaction')

Returns a special InformTransactionComplete packet with status ‘Failed’, to signal to the server that the transaction should be restarted

Example

>>> my_failure = received_packet.reply_with_failure()
>>> client.send_packet(my_failure)
validate_data(raise_on_invalid=False)

By default, checks to see that all required data items have a defined value, unless in_reply_to is not None (in which case, we assume the missing data will be filled in based on the referenced packet ID.

Some packet types will override this function, or add additional checks.

Account packets

AMIE packets relating to accounts

class amieclient.packet.account.DataAccountCreate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
class amieclient.packet.account.NotifyAccountCreate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

class amieclient.packet.account.NotifyAccountInactivate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

class amieclient.packet.account.NotifyAccountReactivate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

class amieclient.packet.account.RequestAccountCreate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

class amieclient.packet.account.RequestAccountInactivate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

class amieclient.packet.account.RequestAccountReactivate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

Project packets

AMIE packets relating to projects

class amieclient.packet.project.DataProjectCreate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
class amieclient.packet.project.NotifyProjectCreate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

class amieclient.packet.project.NotifyProjectInactivate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

class amieclient.packet.project.NotifyProjectReactivate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

class amieclient.packet.project.RequestProjectCreate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

class amieclient.packet.project.RequestProjectInactivate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

class amieclient.packet.project.RequestProjectReactivate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there is only one element in the ResourceList attribute

Person packets

AMIE packets relating to persons

class amieclient.packet.person.NotifyPersonDuplicate(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

Validates that there are no unallowed tags, and additionally checks to make sure that either a global ID or person ID is provided for the two duplicate people

class amieclient.packet.person.NotifyPersonIDs(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
class amieclient.packet.person.RequestPersonMerge(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)

User packets

AMIE packets relating to users

class amieclient.packet.user.NotifyUserModify(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

By default, checks to see that all required data items have a defined value, unless in_reply_to is not None (in which case, we assume the missing data will be filled in based on the referenced packet ID.

Some packet types will override this function, or add additional checks.

class amieclient.packet.user.RequestUserModify(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)
validate_data(raise_on_invalid=False)

By default, checks to see that all required data items have a defined value, unless in_reply_to is not None (in which case, we assume the missing data will be filled in based on the referenced packet ID.

Some packet types will override this function, or add additional checks.

Informational packets

class amieclient.packet.inform.InformTransactionComplete(packet_rec_id=None, trans_rec_id=None, packet_id=None, transaction_id=None, packet_timestamp=None, additional_data=None, in_reply_to=None, client_state=None, client_json=None, remote_site_name=None, local_site_name=None, originating_site_name=None, outgoing_flag=None, transaction_state=None, packet_state=None, type_id=None, _original_data=None, **kwargs)