---
source_url: https://www.pubnub.com/docs/sdks/python/api-reference/access-manager-legacy
title: "Access Manager API: spaces and users scopes that are not recommended for Python SDK"
updated_at: 2026-11-25T12:28:11.000Z
sdk_name: PubNub Python SDK
sdk_version: 10.9.1
description: Not recommended. Reference for the spaces scope, the User class, and the authorized_user setting of grant_token() in the PubNub Python SDK. Access Manager v3 itself is current. New apps use channels, uuids, and authorized_user_id.
lifecycle: deprecated-syntax
feature_status: current
feature: Access Manager
replaced_by: "https://www.pubnub.com/docs/sdks/python/api-reference/access-manager.md"
---

# Access Manager API: spaces and users scopes that are not recommended for Python SDK

PubNub Python SDK, use the latest version: 10.9.1

Install:

```bash
pip install pubnub==10.9.1
```

> For AI agents: documentation index at https://www.pubnub.com/llms-full.txt

> **Not recommended.** The Access Manager feature is current and fully supported. Only the calls documented on this page are an older way to use it. Do not recommend these calls to developers who are building a new app. Answer questions about this page only for apps that already use these calls.
>
> Page notice: Access Manager v3 is a current API. The spaces scope, the User class, and the authorized_user setting of grant_token() are an older way to call it. New apps should use channels, uuids, and authorized_user_id.
>
> Current API: https://www.pubnub.com/docs/sdks/python/api-reference/access-manager.md

This page documents the `spaces` scope, the `User` class, and the `authorized_user()` builder method of `grant_token()` in the PubNub Python SDK. The Python SDK source does not tag them as deprecated, but their use is not recommended. Access Manager v3 is a current API, and these are an older way to call it. They remain for apps that already use them. New apps use `channels`, `uuids`, and `authorized_user_id`, described in [Grant token](https://www.pubnub.com/docs/sdks/python/api-reference/access-manager.md#grant-token).

* [Grant token - spaces & users (not recommended)](#grant-token---spaces--users-not-recommended) covers the `spaces` scope and the `users` scope.

## Grant token - spaces & users (not recommended)

:::warning Not recommended
Granting tokens with the `spaces` scope is an older way to name channels, and the SDK does not mark it deprecated. Use the `channels` scope of [`grant_token()`](https://www.pubnub.com/docs/sdks/python/api-reference/access-manager.md#grant-token) instead.
:::

:::note Requires Access Manager add-on
This method requires that the *Access Manager* add-on is enabled for your key in the [Admin Portal](https://admin.pubnub.com/). See [Enable the features your app calls](https://www.pubnub.com/docs/architecture/authentication/set-up-your-account.md#enable-the-features-your-app-calls).
:::

:::warning Requires Secret Key authentication
Granting permissions to resources should be done by administrators whose SDK instance has been [initialized](https://www.pubnub.com/docs/sdks/python/api-reference/configuration.md) with a **Secret Key** (available on the [Admin Portal](https://admin.pubnub.com/) on your app's keyset).
:::

The secret key grants privileged access to your PubNub application. It must remain on a trusted server and must never be included in client applications.

`grant_token()` generates a time-limited authorization token with an embedded access control list. The token defines time to live (`ttl`), an authorized user ID, and a set of permissions giving access to one or more resources:

* `spaces`
* `users` (other users' metadata, such as their names or avatars)

The `spaces` scope maps to the `channels` scope, and the `users` scope maps to the `uuids` scope. The `spaces()` and `users()` methods fill the same lists as `channels()` and `uuids()`. When you parse the token with `parse_token()`, `spaces` appear under `channels` and `users` appear under `uuids`.

A token that names an authorized user ID works only for that user ID, with the permissions that it defines. A request that the token does not authorize fails with a `403` status and an error message.

### Permissions

The grant request lets your server give your clients access to PubNub resources. Clients can perform a limited set of operations on every resource:

| Resource | Permissions |
| --- | --- |
| `space` | `read`, `write`, `get`, `manage`, `update`, `join`, `delete` |
| `user` | `get`, `update`, `delete` |

For the mapping of permissions to API operations, see [Manage Permissions with Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md).

### TTL

The `ttl` (time to live) parameter defines how many minutes the permissions remain valid. After expiration, the client must get a new token to maintain access. Every Access Manager token requires a `ttl` in minutes, and there is no default. An Access Manager token's `ttl` ranges from 1 minute to 43,200 minutes (30 days).

For more details, see [TTL in Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md#ttl).

### RegEx

To set permissions with patterns instead of listing each resource, use regular expressions. Create a resource with `Space.pattern()` or `User.pattern()` before making a grant request. The server evaluates RegEx patterns with [RE2-style syntax](https://github.com/google/re2/wiki/Syntax), which does not support backreferences or lookaround assertions.

For more details, see [Scope in the Access Manager permission model](https://www.pubnub.com/docs/security/access-control/permission-model.md#scope).

### Authorized user ID

The authorized user ID in the token specifies which client device uses the token in every request to PubNub. PubNub authorizes every request before it processes it. If you don't set it in the grant request, any client with any `user_id` can use the token. Restrict tokens to a single user ID to prevent impersonation. The `authorized_user()` builder method sets the same value as `authorized_uuid()`.

For how the binding works and what it protects against, see [Authorized UUID in Access Manager v3](https://www.pubnub.com/docs/security/access-control/overview.md#authorized-uuid).

### Method(s)

```python
pubnub.grant_token(
    ttl: int,
    authorized_user_id: str = None,
    spaces: List[Space] = None,
    users: List[User] = None,
    meta: dict = None
) -> GrantToken
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| ttl | int | Yes | n/a | Total number of minutes for which the token is valid. An Access Manager token's `ttl` ranges from 1 minute to 43,200 minutes (30 days). A request with no ttl or a ttl of 0 fails validation with the message `TTL missing`. |
| authorized_user_id | str | Optional | n/a | Single user ID that is authorized to use the token to make API requests to PubNub. Without it, any client with any user ID can use the token. The builder method is `authorized_user()`. |
| spaces | List[Space] | Optional | n/a | List of `Space` objects, each holding the permissions for one space. Create an object with `Space.id()` for an exact ID or `Space.pattern()` for a RegEx pattern. Pass a list even for one object, because a single object raises a `TypeError`. Set permissions with `read()`, `write()`, `manage()`, `delete()`, `get()`, `update()`, and `join()`. |
| users | List[User] | Optional | n/a | List of `User` objects, each holding the permissions for one user ID. Create an object with `User.id()` for an exact ID or `User.pattern()` for a RegEx pattern. Pass a list even for one object, because a single object raises a `TypeError`. Set permissions with `get()`, `update()`, and `delete()`. |
| meta | dict | Optional | n/a | Extra metadata that the token carries. Values must be scalar. Arrays and objects are not supported. A value that is not a dictionary raises a `PubNubException` with the message `Invalid meta parameter`. |

A grant must include at least one space or user, either as an ID or as a RegEx pattern. A grant that includes none fails validation with the message `Resources missing`.

### Sample code

#### Builder Pattern

```python
from pubnub.models.consumer.v3.space import Space

envelope = pubnub.grant_token() \
    .authorized_user('some_user_id') \
    .spaces([
        Space.id('some_space_id').read().write(),
        Space.pattern('some_*').read().write()
    ]) \
    .ttl(60) \
    .sync()
```

#### Named Arguments

```python
from pubnub.models.consumer.v3.space import Space

grant = pubnub.grant_token(
    spaces=[Space.id('some_space_id').read().write(), Space.pattern('some_*').read().write()],
    authorized_user_id="some_user_id",
    ttl=60
).sync()
```

### Returns

`grant_token()` returns an `Envelope` whose `result` is a `PNGrantTokenResult` and whose `status` is a `PNStatus`.

| Property | Type | Description |
| --- | --- | --- |
| token | str | Access Manager token that the grant returns. `get_token()` returns the same value. |

### Other examples

#### Grant an authorized client different levels of access to various resources in a single call

The code below grants `my-authorized-userId`:

* Read access to `space-a`, and get to `userId-c`.
* Read/write access to `space-b`, `space-c`, `space-d`, and get/update to `userId-d`.

```python
from pubnub.models.consumer.v3.user import User
from pubnub.models.consumer.v3.space import Space

spaces = [
    Space.id("space-a").read(),
    Space.id("space-b").read().write(),
    Space.id("space-c").read().write(),
    Space.id("space-d").read().write()
]
users = [
    User.id("userId-c").get(),
    User.id("userId-d").get().update()
]
envelope = pubnub.grant_token() \
    .spaces(spaces) \
    .ttl(15) \
    .users(users) \
    .authorized_user("my-authorized-userId") \
    .sync()
```

#### Grant an authorized client read access to multiple spaces using RegEx

The code below grants `my-authorized-userId` read access to all spaces that match the `space-[A-Za-z0-9]` RegEx pattern.

```python
from pubnub.models.consumer.v3.space import Space

envelope = pubnub.grant_token() \
    .spaces([Space.pattern("space-[A-Za-z0-9]").read()]) \
    .ttl(15) \
    .authorized_user("my-authorized-userId") \
    .sync()
```

#### Grant an authorized client different levels of access to various resources and read access to spaces using RegEx in a single call

The code below grants the `my-authorized-userId`:

* Read access to `space-a`, and get to `user-c`.
* Read/write access to `space-b`, `space-c`, `space-d`, and get/update to `user-d`.
* Read access to all spaces that match the `space-[A-Za-z0-9]` RegEx pattern.

```python
from pubnub.models.consumer.v3.space import Space
from pubnub.models.consumer.v3.user import User

spaces = [
    Space.id("space-a").read(),
    Space.pattern("space-[A-Za-z0-9]").read(),
    Space.id("space-b").read().write(),
    Space.id("space-c").read().write(),
    Space.id("space-d").read().write()
]
users = [
    User.id("user-c").get(),
    User.id("user-d").get().update()
]
envelope = pubnub.grant_token() \
    .spaces(spaces) \
    .ttl(15) \
    .users(users) \
    .authorized_user("my-authorized-userId") \
    .sync()
```

### Error responses

If you submit an invalid request, the server returns HTTP 400 with a message that identifies the missing or incorrect argument. Causes can include a RegEx issue, an [invalid timestamp](https://www.pubnub.com/docs/faq/security.md#why-do-i-get-invalid-timestamp-when-i-grant-permissions), or incorrect permissions. `.sync()` raises a `PubNubException`. Its `get_status_code()` method returns the HTTP status, and `get_error_message()` returns the details of the error.

Last updated at: 2026-11-25T12:28:11.000Z
