
Skillsmp Api
- 17 installs
- 6 repo stars
- Updated January 18, 2026
- kevintsai1202/skillmp-api
Helps with backend & apis tasks.
About
skillsmp api is a Claude Code skill for backend & apis. It helps solo builders move faster with AI-assisted coding.
- skillsmp api
- Backend & APIs
- AI-coding skill
Skillsmp Api by the numbers
- 17 all-time installs (skills.sh)
- Ranked #3,475 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Data as of Aug 2, 2026 (Skillselion catalog sync)
npx skills add https://github.com/kevintsai1202/skillmp-api --skill skillsmp-apiAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 17 |
|---|---|
| repo stars | ★ 6 |
| Last updated | January 18, 2026 |
| Repository | kevintsai1202/skillmp-api ↗ |
What it does
Helps with backend & apis tasks.
Files
SkillsMP API Skill
This skill provides search functionality for the SkillsMP skill marketplace, supporting both keyword search and AI semantic search.
Prerequisites
- Python 3.8 or higher
- requests library (
pip install requests) - SkillsMP API Key from skillsmp.com/settings/api
Installation
First-time setup requires installing the requests library:
pip install requests[!NOTE]
This step only needs to be run once. Python's requests library is the only external dependency required.
API Key Configuration
Check if API Key is configured
Before running any search script, check if .env file exists:
# Check if .env exists
test -f .env && echo "Configured" || echo "Not configured"Setup API Key
Option 1: Using setup script (Recommended)
python scripts/setup.py <API_KEY>Option 2: Create .env file directly
Create a .env file with the following content:
SKILLSMP_API_KEY=sk_live_skillsmp_xxxxxxxxxx[!TIP]
Get your API Key from SkillsMP API Settings
---
Features
1. Keyword Search
Search the skill library using keywords.
Usage:
python scripts/search.py "<keyword>" [page] [per_page] [sort]Parameters:
| Parameter | Required | Description |
|---|---|---|
| keyword | ✓ | Search keyword |
| page | Page number, default: 1 | |
| per_page | Items per page, default: 20, max: 100 | |
| sort | stars or recent |
Examples:
# Basic search
python scripts/search.py "SEO"
# With pagination and sorting
python scripts/search.py "web scraper" 1 10 stars---
2. AI Semantic Search
Use AI-powered semantic search (Cloudflare AI).
Usage:
python scripts/ai_search.py "<query>"Parameters:
| Parameter | Required | Description |
|---|---|---|
| query | ✓ | Natural language query |
Examples:
python scripts/ai_search.py "How to create a web scraper"
python scripts/ai_search.py "skills for building REST APIs"---
3. Install Helper
Search skills and get installation command suggestions.
Usage:
python scripts/install_helper.py "<keyword>" [limit]Parameters:
| Parameter | Required | Description |
|---|---|---|
| keyword | ✓ | Skill keyword to search |
| limit | Number of results to show, default: 5 |
Examples:
python scripts/install_helper.py "spring boot"
python scripts/install_helper.py "react" 10Output includes:
- Skill name, author, stars, description
- GitHub search link to find the repository
- Installation command instructions
---
---
Skill Installation
This skill integrates with add-skill CLI to install skills directly from Git repositories.
Supported Agents
| Agent | Identifier | Global Skills Directory |
|---|---|---|
| Antigravity | antigravity | ~/.gemini/antigravity/skills/ |
| Claude Code | claude-code | ~/.claude/skills/ |
| Cursor | cursor | .cursor/skills/ |
| Codex | codex | .codex/skills/ |
| OpenCode | opencode | .opencode/skills/ |
| GitHub Copilot | github-copilot | .github/copilot/skills/ |
| Roo Code | roo | .roo/skills/ |
Install Command References
The add-skill tool installs skills from any Git repository.
Install specific skill to global scope (User-level):
npx add-skill <owner>/<repo> --skill "<skill-name>" -g -a antigravity -yInstall ALL skills from a repo:
npx add-skill <owner>/<repo> -g -a antigravity -yInstall to project scope (Local):
npx add-skill <owner>/<repo> --skill "<skill-name>" -a antigravity -yList available skills in a repo:
npx add-skill <owner>/<repo> --listComplete Installation Workflow
1. Search for skills Use the helper script to find the repository and skill name:
python scripts/install_helper.py "spring boot"2. Verify repository content List all skills available in the repository:
npx add-skill <owner>/<repo> --list3. Install the skill Choose one of the installation commands above. For most cases, use the Global Install:
npx add-skill <owner>/<repo> --skill "<skill-name>" -g -a antigravity -y4. Verify Installation Check if the skill files are created in the agent's skill directory.
---
Response Format
Success Response:
{
"success": true,
"data": {
"skills": [...]
}
}Error Response:
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Error message"
}
}---
Agent Workflow
When a user requests SkillsMP search functionality:
1. Check if `.env` exists
- If exists → Run search script directly
- If not → Guide user through setup
2. Guide user to get API Key
- Direct user to https://skillsmp.com/settings/api
- Ask user to provide the API Key
3. Configure API Key
- Use
setup.pyscript or create.envfile - Verify setup before running search
[!CAUTION]
The .env file contains sensitive information and is excluded from Git.Never share or expose your API Key publicly.
# SkillsMP API 設定
# 複製此檔案為 .env 並填入您的 API key
SKILLSMP_API_KEY=your_api_key_here
# 環境變數檔案(包含敏感資訊)
.env
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
venv/
.venv/
# 系統檔案
.DS_Store
Thumbs.db
SkillsMP API Skill
 
English | 繁體中文
專為 SkillsMP 技能市場打造的通用搜尋與安裝工具。相容於所有支援 SKILL 格式的 AI 代理(如 Claude、Cursor、Windsurf、Antigravity 等)。
✨ 功能特色
- 🔍 關鍵字搜尋 - 快速搜尋 SkillsMP 技能庫
- 🤖 AI 語意搜尋 - 使用 Cloudflare AI 進行智慧語意搜尋
- 📦 安裝輔助工具 - 自動生成技能安裝指令
- ⚡ 一鍵安裝 - 整合
add-skillCLI,支援從 GitHub 直接安裝技能
📋 前置需求
🚀 快速開始
1. 安裝依賴
pip install requests注意:requests 是唯一需要的外部依賴。2. 設定 API Key
方式一:使用設定腳本(推薦)
python scripts/setup.py <YOUR_API_KEY>方式二:手動建立 .env 檔案
複製 .env.example 為 .env 並填入您的 API Key:
cp .env.example .env編輯 .env 檔案:
SKILLSMP_API_KEY=sk_live_skillsmp_xxxxxxxxxx📍 取得 API Key
前往 SkillsMP API 設定頁面 取得您的 API Key
📖 使用方式
關鍵字搜尋
python scripts/search.py "<關鍵字>" [頁碼] [每頁筆數] [排序方式]參數說明:
| 參數 | 必填 | 說明 |
|---|---|---|
| 關鍵字 | ✓ | 搜尋關鍵字 |
| 頁碼 | 頁碼,預設 1 | |
| 每頁筆數 | 每頁筆數,預設 20,最大 100 | |
| 排序方式 | stars 或 recent |
範例:
# 基本搜尋
python scripts/search.py "SEO"
# 指定分頁與排序
python scripts/search.py "web scraper" 1 10 starsAI 語意搜尋
使用自然語言進行智慧搜尋:
python scripts/ai_search.py "<查詢內容>"範例:
python scripts/ai_search.py "如何建立網頁爬蟲"
python scripts/ai_search.py "建立 REST API 的技能"安裝輔助工具
搜尋技能並取得安裝指令建議:
python scripts/install_helper.py "<關鍵字>" [顯示筆數]範例:
# 搜尋 Spring Boot 相關技能
python scripts/install_helper.py "spring boot"
# 顯示前 10 筆結果
python scripts/install_helper.py "react" 10🔧 技能安裝流程
⚠️ 注意
SkillsMP 的技能 ID 無法直接用於 npx add-skill 安裝。請按照以下步驟操作:1. 搜尋技能
使用輔助腳本找到儲存庫與技能名稱:
python scripts/install_helper.py "spring boot"2. 確認儲存庫內容
列出儲存庫中的所有可用技能:
npx add-skill <owner>/<repo> --list3. 安裝技能
安裝特定技能到全域(User-level):
npx add-skill <owner>/<repo> --skill "<skill-name>" -g -a antigravity -y其他安裝選項:
- 安裝該儲存庫所有技能:
npx add-skill <owner>/<repo> -g -a antigravity -y - 安裝到目前專案(Local):
npx add-skill <owner>/<repo> --skill "<skill-name>" -a antigravity -y
4. 驗證安裝 檢查 Agent 的技能目錄,確認檔案已成功建立。
📦 API 回應格式
成功回應
{
"success": true,
"data": {
"skills": [...]
}
}錯誤回應
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "錯誤訊息"
}
}🔐 安全性注意事項
.env檔案包含敏感資訊,已被加入.gitignore,不會上傳到 GitHub- 請妥善保管您的 API Key,切勿公開分享
🌐 相容性
此 Skill 相容於所有支援 SKILL 格式的 AI 代理:
- Claude (Anthropic)
- Cursor
- Windsurf
- Antigravity (Google DeepMind)
- 以及更多...
支援的 Agent 識別符
| Agent | 識別名稱 | 全域技能目錄 |
|---|---|---|
| Antigravity | antigravity | ~/.gemini/antigravity/skills/ |
| Claude Code | claude-code | ~/.claude/skills/ |
| Cursor | cursor | .cursor/skills/ |
| Codex | codex | .codex/skills/ |
| OpenCode | opencode | .opencode/skills/ |
| GitHub Copilot | github-copilot | .github/copilot/skills/ |
| Roo Code | roo | .roo/skills/ |
📄 授權
本專案採用 ISC License 授權。
🔗 相關連結
SkillsMP API Skill
 
English | 繁體中文
A universal skill for searching and discovering AI skills from the SkillsMP marketplace. Compatible with all AI agents that support the SKILL format (Claude, Cursor, Windsurf, Antigravity, etc.).
✨ Features
- 🔍 Keyword Search - Fast keyword-based search of the SkillsMP library
- 🤖 AI Semantic Search - Intelligent semantic search powered by Cloudflare AI
- 📦 Install Helper - Automatically generate skill installation commands
📋 Prerequisites
🚀 Quick Start
1. Install Dependencies
pip install requestsNote: requests is the only external dependency required.2. Configure API Key
Option 1: Using Setup Script (Recommended)
python scripts/setup.py <YOUR_API_KEY>Option 2: Create .env File Manually
Copy .env.example to .env and add your API Key:
cp .env.example .envEdit the .env file:
SKILLSMP_API_KEY=sk_live_skillsmp_xxxxxxxxxx📍 Get Your API Key
Visit the SkillsMP API Settings page to obtain your API Key
📖 Usage
Keyword Search
python scripts/search.py "<keyword>" [page] [per_page] [sort]Parameters:
| Parameter | Required | Description |
|---|---|---|
| keyword | ✓ | Search keyword |
| page | Page number, default: 1 | |
| per_page | Items per page, default: 20, max: 100 | |
| sort | stars or recent |
Examples:
# Basic search
python scripts/search.py "SEO"
# With pagination and sorting
python scripts/search.py "web scraper" 1 10 starsAI Semantic Search
Use natural language for intelligent searching:
python scripts/ai_search.py "<query>"Examples:
python scripts/ai_search.py "How to create a web scraper"
python scripts/ai_search.py "skills for building REST APIs"Install Helper
Search for skills and get installation command suggestions:
python scripts/install_helper.py "<keyword>" [limit]Examples:
# Search for Spring Boot related skills
python scripts/install_helper.py "spring boot"
# Show top 10 results
python scripts/install_helper.py "react" 10📂 Project Structure
skillmp-api/
├── scripts/
│ ├── search.py # Keyword search script
│ ├── ai_search.py # AI semantic search script
│ ├── install_helper.py # Installation helper tool
│ └── setup.py # API Key setup script
├── .env.example # Environment variables example
├── .gitignore # Git ignore file
├── SKILL.md # Skill documentation (for AI agents)
└── README.md # This file🔧 Skill Installation Workflow
⚠️ Note
SkillsMP skill IDs cannot be used directly with npx add-skill. Follow these steps:1. Search for skills Use the helper script to find the repository and skill name:
python scripts/install_helper.py "spring boot"2. Verify repository content
List all skills available in the repository:
npx add-skill <owner>/<repo> --list3. Install the skill
Install specific skill to global scope (User-level):
npx add-skill <owner>/<repo> --skill "<skill-name>" -g -a antigravity -yOther Installation Options:
- Install ALL skills:
npx add-skill <owner>/<repo> -g -a antigravity -y - Install to Local Project:
npx add-skill <owner>/<repo> --skill "<skill-name>" -a antigravity -y
📦 API Response Format
Success Response
{
"success": true,
"data": {
"skills": [...]
}
}Error Response
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Error message"
}
}🔐 Security Notes
- The
.envfile contains sensitive information and is excluded from Git via.gitignore - Never share or expose your API Key publicly
🌐 Compatibility
This skill is compatible with all AI agents that support the SKILL format:
- Claude (Anthropic)
- Cursor
- Windsurf
- Antigravity (Google DeepMind)
- And more...
📄 License
This project is licensed under the ISC License.
🔗 Related Links
# SkillsMP API Skill 依賴套件
requests>=2.28.0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
SkillsMP AI 語意搜尋腳本
使用 AI 語意搜尋 SkillsMP 技能市場 (Cloudflare AI 驅動)
用法: python ai_search.py <query>
參數:
query - AI 搜尋查詢 (必填)
"""
import sys
import json
import os
from pathlib import Path
# 嘗試導入 requests,如果沒有則提示安裝
try:
import requests
except ImportError:
print("錯誤: 請先安裝 requests 套件")
print("執行: pip install requests")
sys.exit(1)
# API 設定
API_BASE_URL = "https://skillsmp.com"
def load_env():
"""
從 .env 檔案載入環境變數
Returns:
dict: 環境變數字典
"""
env_path = Path(__file__).parent.parent / ".env"
env_vars = {}
if env_path.exists():
with open(env_path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
# 跳過空行和註解
if not line or line.startswith("#"):
continue
# 解析 KEY=VALUE 格式
if "=" in line:
key, value = line.split("=", 1)
env_vars[key.strip()] = value.strip()
return env_vars
def get_api_key():
"""
取得 API Key,優先從環境變數,其次從 .env 檔案
Returns:
str: API Key
"""
# 優先從系統環境變數讀取
api_key = os.environ.get("SKILLSMP_API_KEY")
# 如果沒有,從 .env 檔案讀取
if not api_key:
env_vars = load_env()
api_key = env_vars.get("SKILLSMP_API_KEY")
return api_key
def ai_search_skills(query):
"""
執行 AI 語意搜尋
Args:
query: AI 搜尋查詢
Returns:
dict: 搜尋結果
"""
api_key = get_api_key()
if not api_key:
return {
"success": False,
"error": {
"code": "NO_API_KEY",
"message": "請設定環境變數 SKILLSMP_API_KEY"
}
}
url = f"{API_BASE_URL}/api/v1/skills/ai-search"
try:
response = requests.get(
url,
params={"q": query},
headers={"Authorization": f"Bearer {api_key}"}
)
return response.json()
except requests.RequestException as e:
return {
"success": False,
"error": {
"code": "FETCH_ERROR",
"message": str(e)
}
}
def main():
"""主程式入口"""
args = sys.argv[1:]
# 檢查必填參數
if len(args) == 0:
print("錯誤: 請提供 AI 搜尋查詢")
print("用法: python ai_search.py <query>")
sys.exit(1)
# 檢查 API Key
if not get_api_key():
print("錯誤: 請設定環境變數 SKILLSMP_API_KEY")
print("提示: 複製 .env.example 為 .env 並填入您的 API key")
sys.exit(1)
# 合併所有參數作為查詢字串(支援空格)
query = " ".join(args)
print(f'正在進行 AI 語意搜尋: "{query}"')
print("---")
result = ai_search_skills(query)
# 輸出結果
print(json.dumps(result, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
SkillsMP 技能安裝查詢腳本
搜尋技能並提供安裝指令
用法: python install_helper.py <query> [limit]
參數:
query - 搜尋關鍵字 (必填)
limit - 顯示筆數,預設 5
"""
import sys
import json
import os
import re
from pathlib import Path
# 嘗試導入 requests,如果沒有則提示安裝
try:
import requests
except ImportError:
print("錯誤: 請先安裝 requests 套件")
print("執行: pip install requests")
sys.exit(1)
# API 設定
API_BASE_URL = "https://skillsmp.com"
def load_env():
"""
從 .env 檔案載入環境變數
Returns:
dict: 環境變數字典
"""
env_path = Path(__file__).parent.parent / ".env"
env_vars = {}
if env_path.exists():
with open(env_path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
# 跳過空行和註解
if not line or line.startswith("#"):
continue
# 解析 KEY=VALUE 格式
if "=" in line:
key, value = line.split("=", 1)
env_vars[key.strip()] = value.strip()
return env_vars
def get_api_key():
"""
取得 API Key,優先從環境變數,其次從 .env 檔案
Returns:
str: API Key
"""
# 優先從系統環境變數讀取
api_key = os.environ.get("SKILLSMP_API_KEY")
# 如果沒有,從 .env 檔案讀取
if not api_key:
env_vars = load_env()
api_key = env_vars.get("SKILLSMP_API_KEY")
return api_key
def parse_github_url(github_url):
"""
從 GitHub URL 解析 owner/repo
Args:
github_url: GitHub 儲存庫 URL
Returns:
dict 或 None: 包含 owner, repo, fullPath 的字典
"""
if not github_url:
return None
# 格式: https://github.com/owner/repo/tree/branch/path
match = re.search(r"github\.com/([^/]+)/([^/]+)", github_url)
if not match:
return None
owner = match.group(1)
repo = match.group(2)
return {
"owner": owner,
"repo": repo,
"fullPath": f"{owner}/{repo}"
}
def search_skills(query, limit=5):
"""
執行關鍵字搜尋
Args:
query: 搜尋關鍵字
limit: 每頁筆數
Returns:
dict: 搜尋結果
"""
api_key = get_api_key()
if not api_key:
return {
"success": False,
"error": {
"code": "NO_API_KEY",
"message": "請設定環境變數 SKILLSMP_API_KEY"
}
}
url = f"{API_BASE_URL}/api/v1/skills/search"
params = {
"q": query,
"page": 1,
"limit": limit,
"sortBy": "stars"
}
try:
response = requests.get(
url,
params=params,
headers={"Authorization": f"Bearer {api_key}"}
)
return response.json()
except requests.RequestException as e:
return {
"success": False,
"error": {
"code": "FETCH_ERROR",
"message": str(e)
}
}
def select_agent():
"""
讓使用者選擇目標 Agent
Returns:
str: 選擇的 Agent 識別符
"""
agents = {
"1": ("antigravity", "Antigravity (Google DeepMind)"),
"2": ("claude-code", "Claude Code (Anthropic)"),
"3": ("cursor", "Cursor"),
"4": ("roo", "Roo Code"),
"5": ("github-copilot", "GitHub Copilot"),
"a": ("all", "列出所有 Agent 指令")
}
print("請問要安裝到哪個 Agent 環境?")
for key, (agent_id, name) in agents.items():
print(f" [{key}] {name}")
print(" [q] 離開")
while True:
choice = input("\n請選擇 (預設 1): ").strip().lower()
if not choice:
return "antigravity"
if choice == 'q':
sys.exit(0)
if choice in agents:
return agents[choice][0]
print("❌ 無效的選擇,請重試")
def generate_install_command(repo_path, skill_name=None, agent_id="antigravity"):
"""
生成安裝指令
Args:
repo_path: 儲存庫路徑 (owner/repo)
skill_name: 技能名稱 (可選)
agent_id: Agent ID
Returns:
list: 指令列表
"""
commands = []
# 定義 Agent ID 列表
target_agents = [agent_id]
if agent_id == "all":
target_agents = ["antigravity", "claude-code", "cursor"]
for agent in target_agents:
agent_flag = f"-a {agent}"
agent_name = agent.capitalize()
if skill_name:
cmd = f'npx add-skill {repo_path} --skill "{skill_name}" -g {agent_flag} -y'
desc = f"# 安裝到 {agent_name} (全域)"
else:
cmd = f'npx add-skill {repo_path} -g {agent_flag} -y'
desc = f"# 安裝所有技能到 {agent_name} (全域)"
commands.append((desc, cmd))
return commands
def format_output(skills):
"""
格式化輸出技能資訊
Args:
skills: 技能列表
"""
print("\n=== 搜尋結果 ===\n")
# 收集所有唯一的儲存庫
repos = {}
for index, skill in enumerate(skills):
parsed = parse_github_url(skill.get("githubUrl"))
name = skill.get("name") or skill.get("id", "Unknown")
author = skill.get("author", "Unknown")
stars = skill.get("stars", 0)
description = skill.get("description", "")
print(f"【{index + 1}】{name}")
print(f" 作者: {author}")
print(f" ⭐ Stars: {stars}")
if description:
desc = description[:80] + "..." if len(description) > 80 else description
print(f" 說明: {desc}")
if parsed:
print(f" GitHub: {skill.get('githubUrl')}")
# 記錄儲存庫
full_path = parsed["fullPath"]
if full_path not in repos:
repos[full_path] = []
repos[full_path].append(name)
else:
skill_url = skill.get("skillUrl", "")
if skill_url:
print(f" SkillsMP: {skill_url}")
print()
# 輸出快速安裝指令
if repos:
# 詢問目標 Agent
selected_agent = select_agent()
print("\n=== 快速安裝指令 ===\n")
for repo_path, skill_names in repos.items():
print(f"📦 儲存庫: {repo_path}")
print(f"📋 列出可用技能: npx add-skill {repo_path} --list\n")
# 安裝所有技能指令
print(f"⬇️ 安裝該儲存庫所有技能:")
for desc, cmd in generate_install_command(repo_path, agent_id=selected_agent):
print(f" {cmd}")
print()
if skill_names:
print(f"⬇️ 安裝特定技能:")
for name in skill_names:
for desc, cmd in generate_install_command(repo_path, name, selected_agent):
print(f" {cmd}")
print("-" * 40 + "\n")
def main():
"""主程式入口"""
args = sys.argv[1:]
if len(args) == 0:
print("SkillsMP 技能安裝查詢工具")
print()
print("用法: python install_helper.py <query> [limit]")
print()
print("範例:")
print(' python install_helper.py "spring boot"')
print(' python install_helper.py "react" 10')
sys.exit(1)
# 檢查 API Key
if not get_api_key():
print("錯誤: 請設定環境變數 SKILLSMP_API_KEY")
print("提示: 複製 .env.example 為 .env 並填入您的 API key")
sys.exit(1)
query = args[0]
limit = int(args[1]) if len(args) > 1 else 5
print(f'正在搜尋: "{query}" (顯示前 {limit} 筆,依 Stars 排序)')
result = search_skills(query, limit)
if not result.get("success"):
error_msg = result.get("error", {}).get("message", "未知錯誤")
print(f"搜尋失敗: {error_msg}")
sys.exit(1)
skills = result.get("data", {}).get("skills", [])
if not skills:
print("找不到相關技能")
sys.exit(0)
format_output(skills)
total = result.get("data", {}).get("pagination", {}).get("total", len(skills))
print(f"總共找到 {total} 個相關技能")
if __name__ == "__main__":
main()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
SkillsMP 關鍵字搜尋腳本
使用關鍵字搜尋 SkillsMP 技能市場
用法: python search.py <query> [page] [limit] [sortBy]
參數:
query - 搜尋關鍵字 (必填)
page - 頁碼,預設 1
limit - 每頁筆數,預設 20,最大 100
sortBy - 排序方式,可選 'stars' 或 'recent'
"""
import sys
import json
import os
from pathlib import Path
# 嘗試導入 requests,如果沒有則提示安裝
try:
import requests
except ImportError:
print("錯誤: 請先安裝 requests 套件")
print("執行: pip install requests")
sys.exit(1)
# API 設定
API_BASE_URL = "https://skillsmp.com"
def load_env():
"""
從 .env 檔案載入環境變數
Returns:
dict: 環境變數字典
"""
env_path = Path(__file__).parent.parent / ".env"
env_vars = {}
if env_path.exists():
with open(env_path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
# 跳過空行和註解
if not line or line.startswith("#"):
continue
# 解析 KEY=VALUE 格式
if "=" in line:
key, value = line.split("=", 1)
env_vars[key.strip()] = value.strip()
return env_vars
def get_api_key():
"""
取得 API Key,優先從環境變數,其次從 .env 檔案
Returns:
str: API Key
"""
# 優先從系統環境變數讀取
api_key = os.environ.get("SKILLSMP_API_KEY")
# 如果沒有,從 .env 檔案讀取
if not api_key:
env_vars = load_env()
api_key = env_vars.get("SKILLSMP_API_KEY")
return api_key
def search_skills(query, page=1, limit=20, sort_by=None):
"""
執行關鍵字搜尋
Args:
query: 搜尋關鍵字
page: 頁碼
limit: 每頁筆數
sort_by: 排序方式 ('stars' 或 'recent')
Returns:
dict: 搜尋結果
"""
api_key = get_api_key()
if not api_key:
return {
"success": False,
"error": {
"code": "NO_API_KEY",
"message": "請設定環境變數 SKILLSMP_API_KEY"
}
}
# 建立請求參數
params = {
"q": query,
"page": page,
"limit": limit
}
# 加入可選的排序參數
if sort_by and sort_by in ["stars", "recent"]:
params["sortBy"] = sort_by
url = f"{API_BASE_URL}/api/v1/skills/search"
try:
response = requests.get(
url,
params=params,
headers={"Authorization": f"Bearer {api_key}"}
)
return response.json()
except requests.RequestException as e:
return {
"success": False,
"error": {
"code": "FETCH_ERROR",
"message": str(e)
}
}
def main():
"""主程式入口"""
args = sys.argv[1:]
# 檢查必填參數
if len(args) == 0:
print("錯誤: 請提供搜尋關鍵字")
print("用法: python search.py <query> [page] [limit] [sortBy]")
sys.exit(1)
# 檢查 API Key
if not get_api_key():
print("錯誤: 請設定環境變數 SKILLSMP_API_KEY")
print("提示: 複製 .env.example 為 .env 並填入您的 API key")
sys.exit(1)
# 解析參數
query = args[0]
page = int(args[1]) if len(args) > 1 else 1
limit = int(args[2]) if len(args) > 2 else 20
sort_by = args[3] if len(args) > 3 else None
print(f'正在搜尋: "{query}"')
print(f"參數: 頁碼={page}, 每頁={limit}, 排序={sort_by or '預設'}")
print("---")
result = search_skills(query, page, limit, sort_by)
# 輸出結果
print(json.dumps(result, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
SkillsMP API Key 設定腳本
用於設定 .env 檔案中的 API Key
用法: python setup.py <api_key>
參數:
api_key - SkillsMP API Key (必填)
"""
import sys
import re
from pathlib import Path
def is_valid_api_key_format(api_key):
"""
驗證 API Key 格式
Args:
api_key: 要驗證的 API Key
Returns:
bool: 是否為有效格式
"""
# SkillsMP API Key 格式: sk_live_skillsmp_...
pattern = r"^sk_live_skillsmp_[a-zA-Z0-9]+$"
return bool(re.match(pattern, api_key))
def setup_env_file(api_key):
"""
建立或更新 .env 檔案
Args:
api_key: 要儲存的 API Key
"""
env_path = Path(__file__).parent.parent / ".env"
env_content = f"""# SkillsMP API 設定
SKILLSMP_API_KEY={api_key}
"""
try:
with open(env_path, "w", encoding="utf-8") as f:
f.write(env_content)
print("✅ API Key 設定成功!")
print(f"📁 已儲存至: {env_path}")
print()
print("現在您可以執行搜尋腳本:")
print(' python scripts/search.py "關鍵字"')
print(' python scripts/ai_search.py "查詢內容"')
except IOError as e:
print(f"❌ 寫入 .env 檔案失敗: {e}")
sys.exit(1)
def main():
"""主程式入口"""
args = sys.argv[1:]
# 檢查必填參數
if len(args) == 0:
print("SkillsMP API Key 設定工具")
print()
print("用法: python scripts/setup.py <api_key>")
print()
print("如何取得 API Key:")
print(" 1. 前往 https://skillsmp.com 並登入/註冊帳號")
print(" 2. 進入 https://skillsmp.com/settings/api 取得您的 API Key")
print(" 3. API Key 格式為 sk_live_skillsmp_...")
print()
print("範例:")
print(" python scripts/setup.py sk_live_skillsmp_您的金鑰")
sys.exit(1)
api_key = args[0]
# 驗證 API Key 格式
if not is_valid_api_key_format(api_key):
print("❌ API Key 格式無效")
print(" 正確格式: sk_live_skillsmp_...")
print(f" 您輸入的: {api_key}")
sys.exit(1)
# 設定 .env 檔案
setup_env_file(api_key)
if __name__ == "__main__":
main()