# How to Set Notebook Sharing to Public or Restricted via the SharingAPI

> Learn how to set notebook sharing to public or restricted using the SharingAPI in notebooklm-py. Control access easily with simple Python code examples provided.

- Repository: [Teng Lin/notebooklm-py](https://github.com/teng-lin/notebooklm-py)
- Tags: how-to-guide
- Published: 2026-03-09

---

**Use `client.sharing.set_public(notebook_id, True)` to enable public link sharing or `set_public(notebook_id, False)` to restrict access to collaborators only.**

The notebooklm-py client provides granular control over notebook visibility through the `SharingAPI`. Exposed via `client.sharing` on the main client instance, this interface allows you to toggle between public link access and restricted collaborator-only access programmatically. According to the teng-lin/notebooklm-py source code, the implementation maps to internal RPC calls that update sharing permissions in real-time.

## Understanding the SharingAPI Architecture

The `SharingAPI` class in [`src/notebooklm/_sharing.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/_sharing.py) exposes high-level methods that wrap low-level RPC calls to Google's batchexecute endpoints. When you invoke sharing methods, the client sends requests to the `QDyure` endpoint using `RPCMethod.SHARE_NOTEBOOK`.

Key components include:

- **Access levels**: Defined in [`src/notebooklm/types.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/types.py) as `ShareAccess` enum values (`ANYONE_WITH_LINK` or `RESTRICTED`)
- **Status tracking**: The `ShareStatus` dataclass captures the current state including `is_public`, `access` level, and `share_url`
- **RPC types**: [`src/notebooklm/rpc/types.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/rpc/types.py) contains the method identifiers and enum mappings

## Setting Notebook Sharing to Public or Restricted

The primary method for toggling visibility is `set_public(notebook_id, make_public)`. This boolean-driven interface determines whether anyone with the link can access the notebook or if access is limited to explicit collaborators.

### Enabling Public Link Sharing

To make a notebook publicly accessible:

```python
status = await client.sharing.set_public("nb_12345", True)

```

This action sets `ShareAccess.ANYONE_WITH_LINK` in the backend. Upon success, the returned `ShareStatus` object contains a `share_url` field that you can distribute to grant immediate access.

### Restricting Access to Collaborators Only

To revoke public access and return to private collaboration:

```python
status = await client.sharing.set_public("nb_12345", False)

```

This updates the access level to `ShareAccess.RESTRICTED`, ensuring only invited collaborators can view or interact with the notebook.

## Verifying Current Share Status

After modifying permissions, confirm the state using `get_status()`:

```python
current = await client.sharing.get_status(notebook_id)
assert current.access == ShareAccess.RESTRICTED

```

This method returns a fresh `ShareStatus` instance parsed from the API response, reflecting the authoritative server-side state.

## Complete Working Example

The following implementation demonstrates authenticating, toggling sharing modes, and verifying the results:

```python
import asyncio
from notebooklm import NotebookLMClient

async def toggle_sharing(notebook_id: str, make_public: bool):
    # Load credentials from the default storage location

    async with await NotebookLMClient.from_storage() as client:
        # Set notebook sharing to public or restricted via the SharingAPI

        status = await client.sharing.set_public(notebook_id, make_public)

        # Output a short summary

        mode = "public" if status.is_public else "restricted"
        print(f"Notebook {notebook_id} is now {mode}.")
        if status.share_url:
            print(f"Share URL: {status.share_url}")

        # Verify the change with an explicit status check

        refreshed = await client.sharing.get_status(notebook_id)
        assert refreshed.is_public == make_public

# Example usage

if __name__ == "__main__":
    NB_ID = "nb_12345"
    asyncio.run(toggle_sharing(NB_ID, True))   # Make public

    asyncio.run(toggle_sharing(NB_ID, False))  # Re-restrict

```

In [`src/notebooklm/client.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/client.py), the main `NotebookLMClient` class initializes the `sharing` attribute as an instance of `SharingAPI`, making these methods available immediately after authentication.

## Summary

- **Primary method**: Use `SharingAPI.set_public(notebook_id, boolean)` to toggle between public and restricted access
- **Implementation location**: Core logic resides in [`src/notebooklm/_sharing.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/_sharing.py) with type definitions in [`src/notebooklm/types.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/types.py)
- **Return type**: Both `set_public` and `get_status` return `ShareStatus` objects containing `is_public`, `access` enum, and `share_url`
- **RPC details**: Operations invoke `RPCMethod.SHARE_NOTEBOOK` against the `QDyure` endpoint when setting permissions
- **Verification**: Call `client.sharing.get_status(notebook_id)` to retrieve current access levels and confirm changes

## Frequently Asked Questions

### What is the difference between public and restricted sharing in notebooklm-py?

Public sharing (`ShareAccess.ANYONE_WITH_LINK`) generates an accessible URL that requires no authentication, while restricted sharing limits access to users explicitly added as collaborators. The `set_public` method boolean directly maps to these two states.

### Does set_public return the share URL immediately?

Yes, when enabling public access (`set_public(notebook_id, True)`), the returned `ShareStatus` object includes the `share_url` field populated with the public link. If the notebook is restricted, this field will be empty or None.

### Can I check sharing status without modifying it?

Yes, use `await client.sharing.get_status(notebook_id)` to retrieve the current `ShareStatus` without making changes. This method parses the RPC response into a structured object containing `is_public`, `access` level, and available URLs.

### Where are the sharing permissions defined in the source code?

The permission enums and dataclasses are defined in [`src/notebooklm/types.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/types.py) (`ShareAccess`, `ShareStatus`), while the API implementation resides in [`src/notebooklm/_sharing.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/_sharing.py). The RPC method identifiers are located in [`src/notebooklm/rpc/types.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/rpc/types.py).