dataverse-sync
Skill46 starsChanged 9 months agoMITView on GitHub
Sync local repository with Harvard Dataverse archive using the API. Use when uploading, replacing, or deleting files in a Dataverse dataset.
In this repository23 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- brainstormingSkill
- catch-upSkill
- clean-survey-dataSkill
- codexSkill
- datacheckSkill
- discuss-claimsSkill
- docSkill
- geminiSkill
- humanizerSkill
- marginaleffectsSkill
- marp-slideSkill
- napkinSkill
- pdfSkill
- playwrightSkill
- qualtrics-surveySkill
- screenshotSkill
- security-best-practicesSkill
- skill-creatorSkill
- stop-slopSkill
- survey-analysisSkill
- vizSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 23
All requests require the X-Dataverse-key header with your API token:
- Very specific: line 103
When uploading, set directoryLabel in the JSON metadata
- Distinctive: line 104
When uploading ZIPs without a directoryLabel, internal ZIP structure is preserved
- Distinctive: line 108
Delete the old file
- Distinctive: line 109
Add the new file with same directoryLabel
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Harvard Dataverse API Sync
Overview
Sync local files with a Harvard Dataverse dataset using the Native API.
Key API Endpoints
| Action | Endpoint | Method |
| Get dataset metadata | /api/datasets/:persistentId/?persistentId={DOI} | GET |
| Add file | /api/datasets/:persistentId/add?persistentId={DOI} | POST |
| Replace file | /api/files/{file_id}/replace | POST |
| Delete file | /api/files/{file_id} | DELETE |
Authentication
All requests require the X-Dataverse-key header with your API token:
headers = {"X-Dataverse-key": "your-api-token"}Common Operations
Get Dataset Files
import requests
url = "https://dataverse.harvard.edu/api/datasets/:persistentId/"
params = {"persistentId": "doi:10.7910/DVN/XXXXXX"}
headers = {"X-Dataverse-key": API_TOKEN}
response = requests.get(url, params=params, headers=headers)
data = response.json()
files = data["data"]["latestVersion"]["files"]
for f in files:
file_id = f["dataFile"]["id"]
md5 = f["dataFile"].get("md5", "")
filename = f.get("label", f["dataFile"].get("filename"))
directory = f.get("directoryLabel", "")Add File
import json
url = "https://dataverse.harvard.edu/api/datasets/:persistentId/add"
params = {"persistentId": DOI}
headers = {"X-Dataverse-key": API_TOKEN}
json_data = json.dumps({
"directoryLabel": "path/to/directory", # Optional
"categories": [],
})
with open(filepath, "rb") as f:
files = {
"file": (filename, f),
"jsonData": (None, json_data, "application/json"),
}
response = requests.post(url, params=params, headers=headers, files=files)Delete File
url = f"https://dataverse.harvard.edu/api/files/{file_id}"
headers = {"X-Dataverse-key": API_TOKEN}
response = requests.delete(url, headers=headers)Compare Files Using MD5
import hashlib
def compute_md5(filepath):
md5_hash = hashlib.md5()
with open(filepath, "rb") as f:
for chunk in iter(lambda: f.read(8192), b""):
md5_hash.update(chunk)
return md5_hash.hexdigest()Important Notes
Draft vs Published
- Changes to a RELEASED dataset create a new DRAFT version
- User must manually publish the draft via web UI
- Publishing creates a new version (v1.0 → v2.0), same DOI
AWS WAF Restrictions
Harvard Dataverse uses AWS WAF which may block direct uploads of certain file types (.R, .do files).
Workaround: Upload files inside a ZIP archive. See dataverse-upload-zip skill.
Directory Labels
- Files in Dataverse have a
directoryLabelthat defines their folder path - When uploading, set
directoryLabelin the JSON metadata - When uploading ZIPs without a directoryLabel, internal ZIP structure is preserved
File Replacement Strategy
The /api/files/{id}/replace endpoint may return 403 for some file types. Alternative approach:
- Delete the old file
- Add the new file with same directoryLabel
Example Sync Script Structure
def sync(dry_run=True):
# 1. Fetch current Dataverse files
dataverse_files = get_dataset_files() # {path: {id, md5, directoryLabel}}
# 2. Scan local files
local_files = get_local_files() # {path: {local_path, md5}}
# 3. Compare
for path, local_info in local_files.items():
if path in dataverse_files:
if local_info["md5"] != dataverse_files[path]["md5"]:
# Modified - replace
replace_file(...)
else:
# New - add
add_file(...)
# 4. Find deleted
for path in dataverse_files:
if path not in local_files:
# Deleted - optionally remove
delete_file(...)References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

