Subnet 13 Data Universe API
Gravity is a decentralized data collection platform powered by SN13 (Data Universe) on the Bittensor network.
Get Started
To get started using Macrocosmos API you should:
Generate your API key using the instruction from the API Keys page
Ensure that you are using Python 3.9+ or Typescript
📎 Supported Platforms
reddittwitter(X)
More platforms will be supported as subnet capabilities expand.
Install the Macrocosmos API using pip or npm:
pip install macrocosmosnpm install macrocosmosMacrocosmos API should be
version 3.0.0 for Python
version 2.1.1 for Typescript
For upgrade use the command
pip install -U macrocosmosnpm install macrocosmos==2.1.1Choose
GravityClientfor sync tasks. UseAsyncGravityClientif async fits better. Check examples/gravity_workflow_example.py for a complete working example of a data collection CLI you can use for your next big project or to plug right into your data product.
Demo Video
Data Universe API Endpoints
Create a task for Data Collection
The task after the launch gets registered on the network within 20 min. The data is starting to be collected and delivered by miners from the moment of the registration on the Blockchain. The task stays live for 7 days to allow the most data to be collected. After that, the dataset gets built automatically. If you provided an email you’ll get a notification with a download link.
To check the status of the task and the amount of data collected at any time use the endpoint Get status of the task. To start building the dataset prior the 7 days completion, use the endpoint Build dataset.
Body
gravityTasks
List of GravityTask objects
List of task objects. Each must include a topic and a platform (x, reddit, etc.)
name
string
Optional name for the Gravity task. Helpful for organizing jobs.
notificationRequests
List of NotificationRequest objects
List of notification configs. Supports type, address, and redirect_url.
Response
Get status of task
To check the status of the task and the amount of data collected at any time use the endpoint Get status of the task.
If you wish to get further information about the crawlers, you can use the include_crawlers flag or make separate GetCrawler() calls since returning in bulk can be slow.
Body
gravity_task_id
string
The unique identifier of the Gravity task you want to inspect.
include_crawlers
bool
Whether to include details of the associated crawler jobs. Defaults to False.
Response
Build dataset
No need to wait 7 days until the task is complete. If you already collected enough data, you can request your dataset early. Add a notification to get alerted when the dataset is built. Once built, the task gets completed and de-registered.
Body
crawlerId
string
The ID of the completed crawler job you want to convert into a dataset.
notificationRequests
List of NotificationRequest objects
A list of notification objects (e.g., email or webhook). Includes type, address, and redirect_url.
maxRows
int
The maximum number of rows to include in the dataset
Response
Build All Datasets
If your Gravity task consists of multiple crawlers (i.e. multiple sets of request parameters), the BuildAllDatasets call allows you to build the corresponding datasets simultaneously by supplying the build_crawlers_config .
Body
gravity_task_id
string
The task ID of the gravity task you want to collect data from.
build_crawlers_config
dict
A configuration dictionary which allows you to specify the maximum number of rows that you will collect for each individual crawler within the task.
Response
Get status of a build
Watch your dataset build with GetDataset(). Once built, the task gets completed and de-registered.
Body
datasetId
string
The ID of the dataset
Response
Cancel requests
Use CancelDataset() to stop a build. If it's done, that call will purge the dataset.
Body
gravityTaskId (datasetId)
string
Gravity task (dataset) Id
Response
Streaming API ( On Demand Data API)
Run precise, real-time queries using the synchronous Sn13Client to query historical or current data based on users, keywords, and time range on platforms like X (Twitter) and Reddit.
The Streaming API is limited to 1000 posts per request.
As of the latest data-universe release:
Users may select two post-filtering modes via the
keyword_modeparameter:"any": Returns posts that contain any combination of the listed keywords."all": Returns posts that contain all of the keywords (default, if field omitted).
For Reddit requests, the first keyword in the list corresponds to the requested subreddit, and subsequent keywords are treated as normal.
URL mode is mutually exclusive with
usernamesandkeywordsfields. Ifurlis provided,usernamesandkeywordsmust be empty.
Body
source
string
Data source (X or Reddit).
usernames
Array of strings
Default: []
Number of items: <= 10 items
List of usernames to fetch data from. Searches for posts from any of the given usernames.
If usernames are not included, they will not be constrained in the search parameters.
keywords
Array of strings
Default: []
Number of items: <= 5 items
List of keywords to search for. Searches for posts where all given keywords are present.
If keywords are not included in the query, they will not be constrained in the search parameters.
For Reddit:
The first keyword indicates the subreddit (r/all for cross-subreddit queries), and subsequent keywords are text matches.
startDate
string
[Optional]
Start date or datetime (ISO format). Defaults to 24 hours prior to the request time if not specified. Datetimes without time information will be set to midnight (00:00:00) by default.
Datetimes without timezone information will be set to UTC by default.
endDate
string
[Optional]
End date or datetime (ISO format). Defaults to the request time if not specified.
Datetimes without time information will be set to midnight (00:00:00) by default.
Datetimes without timezone information will be set to UTC by default.
limit
integer
[Optional]
Default: 100
Options: [1,...,1000]
Maximum number of items to return.
keywordMode
string
[Optional]
Default: all
Options: all , any
Selects the post-filtering mode:
"any": Returns posts that contain any combination of the listedkeywords."all": Returns posts that contain all of thekeywords
url
string
[Optional]
Single url for URL search mode for X (Twitter)
If url is provided, usernames and keywords must be empty or omitted.
Response
Request Examples
Last updated
