You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PyGithub中使用负限定符筛选GitHub仓库?

在PyGithub中实现GitHub搜索的负向过滤

PyGithub的search_repos方法支持直接传入完整的GitHub搜索查询字符串,和你在网页上用的格式完全一致,不用纠结参数命名问题。直接把包含负向限定符的查询语句作为第一个参数传入即可,完美实现你要的过滤效果。

示例代码

from github import Github

# 初始化Github实例,替换为你的个人访问令牌
g = Github("your_personal_access_token")

# 直接使用网页搜索的完整查询语句
search_query = "tensorflow language:Python archived:False -topic:tutorial"
repos = g.search_repos(search_query)

# 遍历输出符合条件的仓库全名
for repo in repos:
    print(repo.full_name)

动态拼接查询条件

如果需要根据变量动态调整过滤规则,直接拼接字符串就行:

target_keyword = "tensorflow"
exclude_topic = "tutorial"
search_query = f"{target_keyword} language:Python archived:False -topic:{exclude_topic}"

这种方式完全复用GitHub原生的搜索语法,所有正向、负向限定符都能直接生效,既能在搜索阶段就过滤掉无关仓库,又能节省API速率配额。

内容的提问来源于stack exchange,提问作者akalanka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 12:51:58