Skip to main content

A python SDK for receiving updates from the OpenSea Stream API - pushed over websockets

Project description

OpenSea Stream API - python SDK

A python SDK for receiving updates from the OpenSea Stream API - pushed over websockets. We currently support the following event types on a per-collection basis:

  • Item Listed
  • Item Sold
  • Item Transferred
  • Item Metadata updates
  • Item Cancelled
  • Item Received offer
  • Item Received bid

Documentation: https://docs.opensea.io/reference/stream-api-overview

Installation

This module requires Python 3 or later. Python 3

pip install opensea_sdk

Getting Started

Authentication

In order to make onboarding easy, we've integrated the OpenSea Stream API with our existing API key system. The API keys you have been using for the REST API should work here as well. If you don't already have one, request an API key from us here.

Simple example

from opensea_sdk import *

api_key = '' # Your opensea api key

def callback(payload: dict):
    # handle event
    return

Client = OpenseaStreamClient(api_key, Network.MAINNET)
Client.onItemListed('collection-slug', callback)
Client.onItemSold('collection-slug', callback)

Client.startListening()

You can also optionally pass in:

  • a network if you would like to access testnet networks.
    • The default value is Network.MAINNET, which represents the following blockchains: Ethereum, Polygon mainnet, Klaytn mainnet, and Solana mainnet
    • Can also select Network.TESTNET, which represents the following blockchains: Rinkeby, Polygon testnet (Mumbai), and Klaytn testnet (Baobab).

Available Networks

The OpenSea Stream API is available on the following networks:

Mainnet

wss://stream.openseabeta.com/socket

Mainnet support events from the following blockchains: Ethereum, Polygon mainnet, Klaytn mainnet, and Solana mainnet.

Testnet

wss://testnets-stream.openseabeta.com/socket

Testnet support events from the following blockchains: Rinkeby, Polygon testnet (Mumbai), and Klaytn testnet (Baobab).

To create testnet instance of the client, you can create it with the following arguments:

from opensea_sdk import *

api_key = '' # Opensea api key

def callback(payload: dict):
    # handle event
    return

Client = OpenseaStreamClient(api_key, Network.TESTNET)

Manually connecting to the socket (optional)

The client will automatically connect to the socket as soon as you subscribe to the first channel. If you would like to connect to the socket manually (before that), you can do so:

Client.connect()

After successfully connecting to our websocket it is time to listen to specific events you're interested in!

Streaming metadata updates

We will only send out metadata updates when we detect that the metadata provided in tokenURI has changed from what OpenSea has previously cached.

Client.onItemMetadataUpdated('collection-slug', callback)

Streaming item listed events

Client.onItemListed('collection-slug', callback)

Streaming item sold events

Client.onItemSold('collection-slug', callback)

Streaming item transferred events

Client.onItemTransferred('collection-slug', callback)

Streaming bids and offers

Client.onItemReceivedBid('collection-slug', callback)

Client.onItemReceivedOffer('collection-slug', callback)

Streaming order cancellation events

Client.onItemCancelled('collection-slug', callback)

Streaming multiple event types and multiple collections

Client.onEvents(
    ['collection-slug', 'collection_slug']
    [EventTypes.ITEM_RECEIVED_OFFER, EventTypes.ITEM_TRANSFERRED],
    callback
    )

Subscribing to events from all collections

If you'd like to listen to an event from all collections use wildcard * for the slug parameter.

Types

Types are included to make working with our event payload objects easier.

Webhook

You might want to use our predefined but fully Customizable discord webhook management

from opensea_sdk import *
from discord_webhook import DiscordWebhook

webhook = DiscordWebhook(url='') # Webhook Url
api_key = '' # Opensea api key

Client = OpenseaStreamClient(api_key, Network.MAINNET)

Client.onItemListed('collection-slug', Webhook(webhook).send)

Client.startListening()

You can change the color, the footer and the thumbnail of the webhook with the following arguments:

from opensea_sdk import *
from discord_webhook import DiscordWebhook

webhook = DiscordWebhook(url='') # Webhook Url
api_key = '' # Opensea api key

custom_footer = 'My custom footer'
custom_thumbnail = '' # Image url
color_ = '' # Hexadecimal color e.g ff0000 (red)

Client = OpenseaStreamClient(api_key, Network.MAINNET)

Client.onItemListed('collection-slug', Webhook(webhook, color=color_,     thumbnail=custom_thumbnail, footer=custom_footer).send)

Client.startListening()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opensea-stream-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

opensea_stream-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file opensea-stream-0.1.0.tar.gz.

File metadata

  • Download URL: opensea-stream-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for opensea-stream-0.1.0.tar.gz
Algorithm Hash digest
SHA256 33e74bb2a8ed2f195316ce65c99379b89b5d6f39d86ea828d91527ae8a3f31a3
MD5 3d006ee2c6576d6dab95918c6e7c4e12
BLAKE2b-256 7142ce7db24dcc718c641e69dd94ba7fdfbc96bff64621d63eb0299b4d2b34a8

See more details on using hashes here.

File details

Details for the file opensea_stream-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for opensea_stream-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bae7bd27f1590256b11e3f57aa5051c56261aa79b45ea5c789eb5309a663a99e
MD5 1c18ced15dfaa496b3f6852bdc1e146a
BLAKE2b-256 727480d1a2d66b3c979a4194390ec3806811cc9738ce616ff9b13a60cd4e4860

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page