Skip to content

Commit 6bf2ddf

Browse files
authored
Merge pull request #91 from null8626/v1/api-rewrite
feat: rewrite SDK by removing v0 features and adding v1 features
2 parents 40e9bdc + ed9b35c commit 6bf2ddf

36 files changed

Lines changed: 1439 additions & 2292 deletions

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* eol=lf
2+
docs/_static/favicon.ico binary

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
dblpy.egg-info/
21
topggpy.egg-info/
32
topgg/__pycache__/
43
build/

.readthedocs.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
version: 2
2-
3-
sphinx:
4-
configuration: docs/conf.py
5-
62
build:
7-
image: latest
8-
3+
os: ubuntu-24.04
4+
tools:
5+
python: '3.14'
6+
sphinx:
7+
configuration: docs/conf.py
98
python:
10-
version: 3.8
119
install:
12-
- requirements: docs/requirements.txt
10+
- requirements: docs/requirements.txt

LICENSE

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
Copyright 2021 Assanali Mukhanov & Top.gg
1+
The MIT License (MIT)
22

3-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3+
Copyright (c) 2024-2026 null8626 & Top.gg
4+
Copyright (c) 2021-2024 Assanali Mukhanov, Norizon, & Top.gg
45

5-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
612

7-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
prune .github
22
prune .ruff_cache
33
prune docs
4-
prune examples
54
prune tests
65
exclude .gitignore
76
exclude .readthedocs.yml
87
exclude ruff.toml
8+
exclude pytest.ini
99
exclude LICENSE
1010
exclude ISSUE_TEMPLATE.md
1111
exclude PULL_REQUEST_TEMPLATE.md

README.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Top.gg Python SDK
2+
3+
> For more information, see the documentation here: <https://topggpy.rtfd.io>.
4+
5+
The community-maintained Python SDK for Top.gg.
6+
7+
## Chapters
8+
9+
- [Installation](#installation)
10+
- [Setting up](#setting-up)
11+
- [Usage](#usage)
12+
- [Getting your project's information](#getting-your-projects-information)
13+
- [Getting your project's vote information of a user](#getting-your-projects-vote-information-of-a-user)
14+
- [Getting a cursor-based paginated list of votes for your project](#getting-a-cursor-based-paginated-list-of-votes-for-your-project)
15+
- [Posting your bot's application commands list](#posting-your-bots-application-commands-list)
16+
- [Generating widget URLs](#generating-widget-urls)
17+
- [Webhooks](#webhooks)
18+
19+
## Installation
20+
21+
```sh
22+
$ pip install topggpy
23+
```
24+
25+
## Setting up
26+
27+
```py
28+
import topgg
29+
30+
import os
31+
32+
33+
token = os.getenv('TOPGG_TOKEN')
34+
assert token is not None, 'Missing TOPGG_TOKEN environment variable.'
35+
36+
client = topgg.Client(token)
37+
```
38+
39+
## Usage
40+
41+
### Getting your project's information
42+
43+
```py
44+
project = await client.get_self()
45+
```
46+
47+
### Getting your project's vote information of a user
48+
49+
#### Discord ID
50+
51+
```py
52+
vote = await client.get_vote(topgg.UserSource.DISCORD, 661200758510977084)
53+
```
54+
55+
#### Top.gg ID
56+
57+
```py
58+
vote = await client.get_vote(topgg.UserSource.TOPGG, 8226924471638491136)
59+
```
60+
61+
### Getting a cursor-based paginated list of votes for your project
62+
63+
```py
64+
from datetime import datetime
65+
66+
67+
first_page = await client.get_votes(datetime(2026, 1, 1))
68+
69+
for vote in first_page:
70+
print(vote)
71+
72+
second_page = await first_page.next()
73+
74+
for vote in second_page:
75+
print(vote)
76+
77+
third_page = await second_page.next()
78+
```
79+
80+
### Posting your bot's application commands list
81+
82+
#### Discord.py
83+
84+
```py
85+
commands = [command.to_dict() for command in await bot.tree.fetch_commands()]
86+
87+
await client.post_commands(commands)
88+
```
89+
90+
#### Raw
91+
92+
```py
93+
# Array of application commands that
94+
# can be serialized to Discord API's raw JSON format.
95+
await client.post_commands(
96+
[
97+
{
98+
'id': '1',
99+
'type': 1,
100+
'application_id': '1',
101+
'name': 'test',
102+
'description': 'command description',
103+
'default_member_permissions': '',
104+
'version': '1',
105+
}
106+
]
107+
)
108+
```
109+
110+
### Generating widget URLs
111+
112+
#### Large
113+
114+
```py
115+
widget_url = topgg.Widget.large(topgg.Platform.DISCORD, topgg.ProjectType.BOT, 1026525568344264724)
116+
```
117+
118+
#### Votes
119+
120+
```py
121+
widget_url = topgg.Widget.votes(topgg.Platform.DISCORD, topgg.ProjectType.BOT, 1026525568344264724)
122+
```
123+
124+
#### Owner
125+
126+
```py
127+
widget_url = topgg.Widget.owner(topgg.Platform.DISCORD, topgg.ProjectType.BOT, 1026525568344264724)
128+
```
129+
130+
#### Social
131+
132+
```py
133+
widget_url = topgg.Widget.social(topgg.Platform.DISCORD, topgg.ProjectType.BOT, 1026525568344264724)
134+
```
135+
136+
### Webhooks
137+
138+
With express:
139+
140+
```py
141+
import topgg
142+
143+
from aiohttp import web
144+
import os
145+
146+
147+
secret = os.getenv('TOPGG_WEBHOOK_SECRET')
148+
assert secret is not None, 'Missing TOPGG_WEBHOOK_SECRET environment variable.'
149+
150+
# POST /webhook
151+
webhooks = topgg.Webhooks('/webhook', secret)
152+
153+
@webhooks.on(topgg.PayloadType.TEST)
154+
async def test_listener(payload: topgg.TestPayload, trace: str) -> web.Response:
155+
print(payload)
156+
157+
return web.Response(status=204)
158+
159+
await webhooks.start()
160+
```

README.rst

Lines changed: 0 additions & 60 deletions
This file was deleted.

examples/discordpy_example/__main__.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)