Driftstone Docs
Back to landing

SDK

Python

The Driftstone Python SDK wraps the repository API for creating repositories, branching work, reading and writing files, merging changes, and syncing branch state.

pip install driftstone

from driftstone import Driftstone

client = Driftstone(api_key="dk-...")

repo = client.repos.create(
    "hello-world",
    initial_files={"README.md": "# Example Repo\n"},
)

branch = client.repos.create_branch(
    "hello-world",
    "feature/readme",
    from_ref=repo.default_branch,
)

client.repos.write_file(
    "hello-world",
    "README.md",
    branch=branch.name,
    message="Update README",
    content="# Example Repo\nUpdated content.\n",
)

client.repos.merge(
    "hello-world",
    head=branch.name,
    base=repo.default_branch,
    message="Merge README update",
)

The client exposes repository operations through client.repos. The longer form client.repositories is also available.

# Repositories
repo = client.repos.create(
    "hello-world",
    initial_files={"README.md": "# Example Repo\n"},
    default_branch="main",
    replace_if_exists=True,
)
repo = client.repos.get("hello-world")

# Branches
branches = client.repos.list_branches("hello-world")
branch = client.repos.get_branch("hello-world", "main")
branch = client.repos.create_branch(
    "hello-world",
    "feature/readme",
    from_ref="main",
)

# Contents
readme = client.repos.read_file("hello-world", "README.md", branch="main")
write = client.repos.write_file(
    "hello-world",
    "README.md",
    branch="feature/readme",
    message="Update README",
    content="# Example Repo\n",
)

# Merge and sync
merge = client.repos.merge(
    "hello-world",
    head="feature/readme",
    base="main",
    message="Merge feature/readme",
)
sync = client.repos.sync(
    "hello-world",
    branch="main",
    target_branches=["production"],
)