pytx.common package

Module contents

class pytx.common.Common(**kwargs)[source]

Bases: object

access_token None[source]

Returns the combined APP-ID and APP-SECRET stored during init().

Returns:str
add_connection(object_id)[source]

Use HTTP POST and add a connection between two objects.

Parameters:object_id (str) – The other object-id in the connection.
Returns:dict (using json.loads())
delete_connection(object_id)[source]

Use HTTP DELETE and remove the connection to another object.

Parameters:object_id (str) – The other object-id in the connection.
Returns:dict (using json.loads())
classmethod details(cls_or_self, id=None, fields=None, connection=None, full_response=False, dict_generator=False, metadata=False)[source]

Get object details. Allows you to limit the fields returned in the object’s details. Also allows you to provide a connection. If a connection is provided, the related objects will be returned instead of the object itself.

NOTE: This method can be used on both instantiated and uninstantiated classes like so:

foo = ThreatIndicator(id=‘1234’) foo.details()

foo = ThreatIndicator.details(id=‘1234’)

BE AWARE: Due to the nature of ThreatExchange allowing you to query for an object by ID but not actually telling you the type of object returned to you, using an ID for an object of a different type (ex: ID for a Malware object using ThreatIndicator class) will result in the wrong object populated with only data that is common between the two objects.

Parameters:
  • id (str) – The ID of the object to get details for if the class is not instantiated.
  • fields (None, str, list) – The fields to limit the details to.
  • connection (None, str) – The connection to find other related objects with.
  • full_response (bool) – Return the full response instead of the generator. Takes precedence over dict_generator.
  • dict_generator (bool) – Return a dictionary instead of an instantiated object.
  • metadata (bool) – Get extra metadata in the response.
Returns:

Generator, dict, class

expire(timestamp)[source]

Expire by setting the ‘expired_on’ timestamp.

Parameters:timestamp (str) – The timestamp to set for an expiration date.
false_positive(object_id)[source]

Mark an object as a false positive by setting the status to UNKNOWN.

Parameters:object_id (str) – The object-id of the object to mark.
get(attr)[source]

Wrapper around __getattr__ making it easier to use the vocabulary to get class attributes.

Parameters:attr (str) – The name of the attribute to get.
classmethod objects(text=None, strict_text=False, type_=None, threat_type=None, fields=None, limit=None, since=None, until=None, __raw__=None, full_response=False, dict_generator=False)[source]

Get objects from ThreatExchange.

Parameters:
  • text (str) – The text used for limiting the search.
  • strict_text (bool, str, int) – Whether we should use strict searching.
  • type (str) – The Indicator type to limit to.
  • threat_type (str) – The Threat type to limit to.
  • fields (str, list) – Select specific fields to pull
  • limit (int, str) – The maximum number of objects to return.
  • since (str) – The timestamp to limit the beginning of the search.
  • until (str) – The timestamp to limit the end of the search.
  • __raw__ (dict) – Provide a dictionary to force as GET parameters. Overrides all other arguments.
  • full_response (bool) – Return the full response instead of the generator. Takes precedence over dict_generator.
  • dict_generator – Return a dictionary instead of an instantiated object.
Returns:

Generator, dict (using json.loads())

populate(attrs)[source]

Given a dictionary, populate self with the keys as attributes.

Parameters:attrs (dict) – A dictionary used as attributes and values.
save()[source]

Save this object. If it is a new object, use self._fields to build the POST and submit to the appropriate URL. If it is an update to an existing object, use self._changed to only submit the modified attributes in the POST.

Returns:dict (using json.loads())
set(name, value)[source]

Wrapper around __setattr__ making it easier to use the vocabulary to set class attributes.

Parameters:
  • name (str) – The name of the attribute to set.
  • value (None, int, str, bool) – The value to set the attribute to.
to_dict()[source]

Convert this object into a dictionary.

Returns:dict
class pytx.common.class_or_instance_method(func)[source]

Bases: object

Custom decorator. This binds to the class if no instance is avaialble, otherwise it will bind to the instance.

This allows us to use a single method which can take both “self” and “cls” as the first argument.

Table Of Contents

This Page