Activity Feeds v3 is in beta — try it out!

Activities

Creating Activities

The example below shows how to create an activity and add it to a feed.

response = self.client.feeds.add_activity(
    type="post",
    feeds=[self.test_feed.get_feed_identifier()],
    text="This is a test activity from Python SDK",
    user_id=self.test_user_id,
    custom={
        "test_field": "test_value",
        "timestamp": int(datetime.now().timestamp()),
    },
)

The above example was quite simple. Here are a few more examples:

Image & Video

response = self.client.feeds.add_activity(
    type="video",
    feeds=[self.test_feed.get_feed_identifier()],
    text="Check out this amazing video!",
    user_id=self.test_user_id,
    attachments=[
        Attachment(
            custom={"duration": 120},
            asset_url="https://example.com/amazing-video.mp4",
            type="video",
            title="Amazing Video",
        )
    ],
    custom={"video_quality": "4K", "duration_seconds": 120},
)

Overview of All Activity Fields

Here’s an overview of all the fields you can add when creating an activity:

FieldDescription
idEither set your own id, or let our server generate it. Setting your own ID can be convenient if your activity maps 1 to 1 to something in your database.
typeThe type of activity. Defaults to “post” if not provided.
feedsThe list of feeds (format: “group id:feed id”) to add this activity to
textThe text for this activity
attachmentsA list of attachments. Video, images, location, etc. Also supports custom attachments
customAny custom data you want to add
visibilityVisibility levels for the activity
locationSpecify an activity location. This allows for feeds to show content close to you. Format: ActivityLocation(lat: 40.014984, lng: -105.270546)
expiresAtWhen the activity expires. After this timestamp it’s only visible to the person who created this activity (or server side API calls)
mentionedUserIdsA list of users mentioned in this activity
parentIdThe parent activity. Used for replies/reshares etc
searchDataAny extra data you want to search on for this activity
filterTagsArray of strings that you can filter on when querying the feed
interestTagsEither set the interest tags manually or enable an activity processor to have AI determine the topics for this activity. Used for “for you” style feeds

Adding Many Activities

You can also batch add activities. Here’s an example:

activities = [
    ActivityRequest(
        type="post",
        text="Batch activity 1",
        user_id=self.test_user_id,
        feeds=[self.test_feed.get_feed_identifier()],
    ),
    ActivityRequest(
        type="post",
        text="Batch activity 2",
        user_id=self.test_user_id,
        feeds=[self.test_feed.get_feed_identifier()],
    ),
]

response = self.client.feeds.upsert_activities(activities=activities)

Updating & Deleting Activities

This example shows how to update or delete an activity:

response = self.client.feeds.update_activity(
    activity_id,
    text="Updated activity text from Python SDK",
    user_id=self.test_user_id,  # Required for server-side auth
    custom={"updated": True, "update_time": int(datetime.now().timestamp())},
)

Partial activity updates

A partial update can be used to set and unset specific fields when it is necessary to retain additional custom data fields on the object. AKA a patch style update. Both set and unset can be used in the same request. The dotted-notation is also available for both set and unset for the custom field.

// Partially set some fields
response = self.client.feeds.update_activity_partial(
    activity_id,
    user_id=self.test_user_id,  # Required for server-side auth
    set={
        "text": "Japan has over 6,800 islands.",
        "custom": {
            "topic": "fun facts",
            "color": "blue",
        }
    }
)

// Partially unset some fields
response = self.client.feeds.update_activity_partial(
    activity_id,
    user_id=self.test_user_id,  # Required for server-side auth
    unset=["custom.color"]
)
© Getstream.io, Inc. All Rights Reserved.