Skip to content

Commit 7443694

Browse files
committed
Initial commit
0 parents  commit 7443694

33 files changed

+1191
-0
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PARTFUSE_RAPIDAPI_KEY=your_key_here
2+
PARTFUSE_RAPIDAPI_HOST=partfuse.p.rapidapi.com
3+
PARTFUSE_BASE_URL=https://partfuse.p.rapidapi.com

.github/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# GitHub Actions
2+
3+
This workflow runs a simple health check using the curl examples.
4+
5+
## Secrets
6+
7+
To enable the workflow, add the following repository secret:
8+
- `PARTFUSE_RAPIDAPI_KEY`
9+
10+
If the secret is missing, the workflow will skip gracefully.

.github/workflows/smoke-test.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Smoke Test
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
smoke-test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Check Health
15+
env:
16+
PARTFUSE_RAPIDAPI_KEY: ${{ secrets.PARTFUSE_RAPIDAPI_KEY }}
17+
run: |
18+
if [ -z "$PARTFUSE_RAPIDAPI_KEY" ]; then
19+
echo "Skipping test: PARTFUSE_RAPIDAPI_KEY not found in secrets"
20+
exit 0
21+
fi
22+
23+
echo "Running health check..."
24+
cd curl
25+
chmod +x health.sh
26+
./health.sh

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Environment variables
2+
.env
3+
.env.local
4+
5+
# Python
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
venv/
10+
.venv/
11+
.pytest_cache/
12+
13+
# Node
14+
node_modules/
15+
npm-debug.log*
16+
yarn-debug.log*
17+
yarn-error.log*
18+
19+
# Go
20+
bin/
21+
22+
# OS
23+
.DS_Store
24+
Thumbs.db

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 PartFuse
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# PartFuse Examples
2+
3+
> **Unified Electronic Components Pricing & Stock API**
4+
>
5+
> Connect to the PartFuse API to search and compare electronic component prices and stock from major distributors (TME, Mouser, DigiKey) in one unified interface.
6+
7+
[**Get your API Key on RapidAPI**](https://rapidapi.com/krystofcelba-jjINWODhz/api/partfuse)
8+
9+
---
10+
11+
## ⚡ Verified in 10 Seconds
12+
13+
Run this to see it working immediately (replace `YOUR_KEY`):
14+
15+
```bash
16+
curl -s "https://partfuse.p.rapidapi.com/ping" \
17+
-H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \
18+
-H "X-RapidAPI-Host: partfuse.p.rapidapi.com"
19+
```
20+
21+
---
22+
23+
## 🚀 Quickstart
24+
25+
1. **Get your API Key** from [RapidAPI](https://rapidapi.com/krystofcelba-jjINWODhz/api/partfuse).
26+
2. **Clone this repository**:
27+
```bash
28+
git clone https://github.com/PartFuse/partfuse-examples.git
29+
cd partfuse-examples
30+
```
31+
3. **Choose your language** and follow the instructions in the respective folder:
32+
33+
| Language | Folder | Description |
34+
| :--- | :--- | :--- |
35+
| **Shell** | [`/curl`](./curl) | Simple `curl` scripts for quick testing. |
36+
| **Python** | [`/python`](./python) | Sync (`requests`) and Async (`httpx`) examples with retries. |
37+
| **Node.js** | [`/node`](./node) | Examples using `fetch` and `axios`. |
38+
| **Go** | [`/go`](./go) | A simple CLI tool written in Go. |
39+
| **Postman** | [`/postman`](./postman) | Collection and environment for Postman. |
40+
41+
---
42+
43+
## 🔑 Authentication
44+
45+
PartFuse is hosted on **RapidAPI**. You must include the following headers in every request:
46+
47+
```http
48+
X-RapidAPI-Key: YOUR_RAPIDAPI_KEY
49+
X-RapidAPI-Host: partfuse.p.rapidapi.com
50+
```
51+
52+
### Environment Variables
53+
54+
All examples in this repository use the following environment variables. Copy the `.env.example` file in the respective language folder to `.env` and fill in your key.
55+
56+
```bash
57+
# Required
58+
PARTFUSE_RAPIDAPI_KEY=your_actual_api_key_here
59+
60+
# Optional (defaults used if not provided)
61+
PARTFUSE_RAPIDAPI_HOST=partfuse.p.rapidapi.com
62+
PARTFUSE_BASE_URL=https://partfuse.p.rapidapi.com
63+
```
64+
65+
---
66+
67+
## 🔗 Endpoints
68+
69+
**Base URL**: `https://partfuse.p.rapidapi.com`
70+
71+
| Method | Endpoint | Description |
72+
| :--- | :--- | :--- |
73+
| `GET` | `/ping` | Liveness probe. Returns 200 OK immediately (no upstream checks). |
74+
| `GET` | `/health` | Health check of internal services and suppliers. |
75+
| `GET` | `/api/v1/search` | Search for parts. Params: `q` (query), `qty` (default 1), `limit` (default 10). |
76+
| `GET` | `/api/v1/compare/{part_number}` | Get real-time pricing & stock. Params: `qty` (default 1). |
77+
| `POST` | `/api/v1/bom/compare` | Bulk pricing for multiple parts. Body: JSON BOM. |
78+
79+
---
80+
81+
## 📡 API Best Practices
82+
83+
### Error Handling & Quotas
84+
- **429 Too Many Requests**: You have exceeded a limit. This limit can be reached in two ways:
85+
- **RapidAPI Plan Limit**: You hit the daily/monthly request cap of your subscribed tier.
86+
- **Internal Monthly Credits**: You exhausted the internal usage credits allocated to your specific API key.
87+
88+
**Advice**: Rate limits are strict. You should implement exponential backoff with jitter and always respect the `Retry-After` header if provided.
89+
90+
- **Partial Results**: The `offers` list may contain statuses like `supplier_unavailable` or `timeout`. Your application should handle these gracefully (e.g., "Supplier X unavailable").
91+
92+
### Data Freshness
93+
- **Caching**: Data is typically cached for **15–60 minutes**.
94+
- **Currencies**: Responses may contain prices in different currencies. Always use the `currency` field provided in each offer object rather than assuming a default.
95+
96+
---
97+
98+
## 🚫 Use Case Limitations
99+
100+
PartFuse is **NOT** designed for:
101+
- **Consumer browsing**: Do not use this as a backend for a general-purpose e-commerce browsing experience.
102+
- **Checkout/Ordering**: This API provides *information* only. You cannot place orders through PartFuse.
103+
- **Contractual SLA**: The service is best-effort.
104+
105+
---
106+
107+
## 💬 Support
108+
109+
Need help? Use the [Discussions tab on RapidAPI](https://rapidapi.com/krystofcelba-jjINWODhz/api/partfuse/discussions).
110+
111+
---
112+
113+
## ❓ FAQ
114+
115+
**Q: What happens if I exceed my quota?**
116+
A: You will receive a `429 Too Many Requests` error. Check your usage in the [RapidAPI Dashboard](https://rapidapi.com/developer/dashboard).
117+
118+
**Q: How do I see my usage?**
119+
A: Visit the [RapidAPI Developer Dashboard](https://rapidapi.com/developer/dashboard) to track your API calls and remaining quota.
120+
121+
**Q: A supplier returned "timeout". What does that mean?**
122+
A: It means the upstream supplier API did not respond within our timeout window. This happens occasionally; you can try the request again later.
123+
124+
---
125+
126+
## 📄 License
127+
128+
This repository is licensed under the **MIT License**.
129+
130+
**Disclaimer**: This project allows access to third-party data. Data accuracy is best-effort and not guaranteed. No purchasing capabilities are provided.

curl/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Curl Examples
2+
3+
These scripts demonstrate how to call the PartFuse API using `curl`.
4+
5+
## Setup
6+
7+
1. Copy `.env.example` from the root to `.env` in the root directory and fill in your RapidAPI Key.
8+
2. Make scripts executable:
9+
```bash
10+
chmod +x *.sh
11+
```
12+
13+
## Usage
14+
15+
```bash
16+
# Search
17+
./search.sh "LM7805"
18+
19+
# Compare
20+
./compare.sh "STM32F103C8T6" 10
21+
22+
# BOM Compare
23+
./bom_compare.sh
24+
25+
# Health/Ping
26+
./health.sh
27+
./ping.sh
28+
```
29+
30+
## Dependencies
31+
- `curl`
32+
- `jq` (optional, for pretty printing json output if you want to pipe: `./search.sh | jq`)

curl/bom_compare.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
if [ -f ../.env ]; then
4+
export $(cat ../.env | grep -v '#' | awk '/=/ {print $1}')
5+
fi
6+
7+
PARTFUSE_RAPIDAPI_KEY=${PARTFUSE_RAPIDAPI_KEY:-""}
8+
PARTFUSE_RAPIDAPI_HOST=${PARTFUSE_RAPIDAPI_HOST:-"partfuse.p.rapidapi.com"}
9+
PARTFUSE_BASE_URL=${PARTFUSE_BASE_URL:-"https://partfuse.p.rapidapi.com"}
10+
11+
if [ -z "$PARTFUSE_RAPIDAPI_KEY" ]; then
12+
echo "Error: PARTFUSE_RAPIDAPI_KEY is not set."
13+
exit 1
14+
fi
15+
16+
# Create a temporary BOM file if not exists
17+
cat <<EOF > temp_bom.json
18+
{
19+
"lines": [
20+
{ "mpn": "LM7805", "quantity": 10, "reference": "U1" },
21+
{ "mpn": "NE555", "quantity": 50, "reference": "U2" }
22+
]
23+
}
24+
EOF
25+
26+
echo "Uploading BOM comparison..."
27+
28+
curl -s --request POST \
29+
--url "$PARTFUSE_BASE_URL/api/v1/bom/compare" \
30+
--header "Content-Type: application/json" \
31+
--header "X-RapidAPI-Key: $PARTFUSE_RAPIDAPI_KEY" \
32+
--header "X-RapidAPI-Host: $PARTFUSE_RAPIDAPI_HOST" \
33+
--data @temp_bom.json
34+
35+
rm temp_bom.json

curl/compare.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
if [ -f ../.env ]; then
4+
export $(cat ../.env | grep -v '#' | awk '/=/ {print $1}')
5+
fi
6+
7+
PARTFUSE_RAPIDAPI_KEY=${PARTFUSE_RAPIDAPI_KEY:-""}
8+
PARTFUSE_RAPIDAPI_HOST=${PARTFUSE_RAPIDAPI_HOST:-"partfuse.p.rapidapi.com"}
9+
PARTFUSE_BASE_URL=${PARTFUSE_BASE_URL:-"https://partfuse.p.rapidapi.com"}
10+
11+
if [ -z "$PARTFUSE_RAPIDAPI_KEY" ]; then
12+
echo "Error: PARTFUSE_RAPIDAPI_KEY is not set."
13+
exit 1
14+
fi
15+
16+
PART_NUMBER=${1:-"STM32F103C8T6"}
17+
QTY=${2:-1}
18+
19+
echo "Comparing prices for: $PART_NUMBER (Qty: $QTY)"
20+
21+
curl -s --request GET \
22+
--url "$PARTFUSE_BASE_URL/api/v1/compare/$PART_NUMBER?qty=$QTY" \
23+
--header "X-RapidAPI-Key: $PARTFUSE_RAPIDAPI_KEY" \
24+
--header "X-RapidAPI-Host: $PARTFUSE_RAPIDAPI_HOST"

curl/health.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
if [ -f ../.env ]; then
4+
export $(cat ../.env | grep -v '#' | awk '/=/ {print $1}')
5+
fi
6+
7+
PARTFUSE_RAPIDAPI_KEY=${PARTFUSE_RAPIDAPI_KEY:-""}
8+
PARTFUSE_RAPIDAPI_HOST=${PARTFUSE_RAPIDAPI_HOST:-"partfuse.p.rapidapi.com"}
9+
PARTFUSE_BASE_URL=${PARTFUSE_BASE_URL:-"https://partfuse.p.rapidapi.com"}
10+
11+
# Health technically doesn't require auth on some setups, but RapidAPI always enforces headers
12+
if [ -z "$PARTFUSE_RAPIDAPI_KEY" ]; then
13+
echo "Error: PARTFUSE_RAPIDAPI_KEY is not set."
14+
exit 1
15+
fi
16+
17+
echo "Checking Health..."
18+
19+
curl -s --request GET \
20+
--url "$PARTFUSE_BASE_URL/health" \
21+
--header "X-RapidAPI-Key: $PARTFUSE_RAPIDAPI_KEY" \
22+
--header "X-RapidAPI-Host: $PARTFUSE_RAPIDAPI_HOST"

0 commit comments

Comments
 (0)