fake-sg
A better mockgun: a local test server for Shotgun / ShotGrid / Flow Production Tracking (FlowPT), backed by SQLite and written in Rust.
Instead of replacing the Python shotgun_api3 client, you point shotgun_api3
at fake-sg just like a real server.
Status:
fake-sgis a work in progress. See COMPATIBILITY.md for what currently works and known limitations.
Why use fake-sg instead of mockgun?
Python's built-in mockgun is great for simple unit tests, but it breaks down
for realistic integration tests:
- Shared server across processes:
mockgunonly lives inside one Python process.fake-sgruns as a real web server, so multiple containers or processes can share the same test data (for example, a backend container and a frontend Playwright test). - Synced relationships:
fake-sgstores data in SQLite tables, including connection tables for many-to-many links. Updating a relationship from one side updates the other side too (such as a Project'susersand each User'sprojects). - Closer to real Shotgun:
fake-sgaims to match real server behavior for dates, deep dotted field lookups (likeentity.Shot.project.Project.code), and API methods, including Note threads, activity streams, project navigation, and configured Page CSV exports.
Not every Shotgun feature is implemented yet—check COMPATIBILITY.md for current coverage.
Quick start
1. Install
Released versions are on PyPI with prebuilt wheels for Linux (glibc and musl), macOS, and Windows on x86_64 and arm64:
pip install fake-sg
This installs both the fake_sg Python module and the fake-sg command line
tool. The command is a native Rust executable and does not use Python, so you
can also download it on its own from the
GitHub releases page. The commands below use cargo run --;
with an installed release, run fake-sg instead.
To build from source, install:
Build the Python package and set up the local environment:
uv sync
2. Clone a Shotgun schema
fake-sg needs a SQLite database cloned from a real Shotgun site so it knows
your entity types and fields.
# Set SHOTGUN_SERVER, SHOTGUN_LOGIN, and SHOTGUN_PASSWORD in your environment.
cargo run -- clone-schema --output schema.sqlite
See Cloning a Shotgun site below for Python usage, API-key auth, and copying data.
3. Start the server
From Python
from fake_sg import start_server
from shotgun_api3 import Shotgun
port = start_server("schema.sqlite") # Picks a free port (or pass port=3000)
sg = Shotgun(f"http://127.0.0.1:{port}", script_name="test", api_key="test")
If permission data was cloned, requests require a copied user or script with a matching name and an assigned cloned role; see Site permissions.
By default the server accepts any password or script key for any login or
script name, so tests can connect without stored credentials. Pass
authentication=True (or --authentication on the command line) to require a
password or key that matches the salted hash stored for an active account:
port = start_server("schema.sqlite", authentication=True)
sg = Shotgun(f"http://127.0.0.1:{port}", login="alice", password="alice-pw")
Set passwords and keys through the API (HumanUser.password_proxy and
ApiUser.salted_password) or when cloning (see below). Either way,
get_session_token() creates a real session, stored in the database so servers
sharing it accept the same tokens; unknown or expired tokens are rejected.
Sessions expire after the site's session_expiry preference (24 hours by
default) without use. sudo_as_login acts as another user; with
authentication on, the caller's role must allow it and the target must be an
active user.
start_server starts the server in the background and returns once it is ready
to accept connections. The server shuts down automatically when Python exits
normally (forced exits like os._exit skip cleanup).
Uploaded files and thumbnails are stored in SQLite by default, with a 64 MiB
per-file limit. Pass file_storage to start_server (or --file-storage to
the CLI) to keep file bytes in that directory instead; SQLite retains metadata
only, and directory storage has no per-file size limit.
port = start_server("schema.sqlite", file_storage="uploads")
Like the reference server, a site without subscription management,
user_subscriptions_read() and user_subscriptions_create() fail with
Not Found. Pass user_subscriptions=True (or --user-subscriptions) to store
subscriptions locally instead, following shotgun_api3's documented contract.
By default, mutations write directly to the on-disk SQLite file. Pass
in_memory=True to start_server (or --in-memory on the command line) to
load the on-disk database into an isolated, ephemeral in-memory copy instead.
This leaves the source file untouched, which is useful when unit tests reuse
one shared schema database and each test wants a fresh copy:
port = start_server("schema.sqlite", in_memory=True)
From the command line
cargo run -- schema.sqlite
cargo run -- schema.sqlite --in-memory # Run against an ephemeral in-memory copy
cargo run -- schema.sqlite --authentication # Check passwords and keys
cargo run -- schema.sqlite --file-storage uploads # Store file bytes outside SQLite
cargo run -- schema.sqlite --user-subscriptions # Store user subscriptions locally
This starts the server on port 3000. Open http://localhost:3000/ to confirm
it responds with Server running.
Both entry points require an existing cloned database; missing or invalid files
fail startup immediately. The server listens on 0.0.0.0 so containers and
other local tools can reach it. This is a test server—do not expose it to
untrusted networks.
Cloning a Shotgun site
You can clone just the schema (no records), all API-visible records, or only selected entity types.
From the command line
# Schema only (default)
cargo run -- clone-schema --output schema.sqlite
# Schema + all API-visible records
cargo run -- clone-schema --output all.sqlite --all-data
# Schema + records for specific entity types
cargo run -- clone-schema --output selected.sqlite --entity-type Project --entity-type HumanUser
# Copy records and download attachments and thumbnails into SQLite
cargo run -- clone-schema --output all.sqlite --all-data --download-files
# Or download file bytes into an empty directory
cargo run -- clone-schema --output all.sqlite --all-data --file-storage uploads
# Give every copied user and script a password, and one user its own
cargo run -- clone-schema --output all.sqlite --all-data \
--account-password '*=test-password' --account-password alice=alice-pw
From Python
from fake_sg import clone_schema
# Schema only
clone_schema(server, "schema.sqlite", login=login, password=password)
# Using a script name and API key instead of a user login
clone_schema(server, "schema.sqlite", script_name=name, api_key=key)
# Copy all records
clone_schema(server, "all.sqlite", login=login, password=password, all_data=True)
# Copy records and download attachments, images, and filmstrips into SQLite
clone_schema(
server, "with-files.sqlite", login=login, password=password,
all_data=True, download_files=True,
)
# Store downloaded file bytes in an empty directory instead
clone_schema(
server, "with-files.sqlite", login=login, password=password,
all_data=True, file_storage="uploads",
)
# Copy only specific entity types
clone_schema(
server,
"selected.sqlite",
login=login,
password=password,
entity_types=["Project", "HumanUser"],
)
# Store passwords for copied accounts ("*" means every user and script)
clone_schema(
server,
"all.sqlite",
login=login,
password=password,
all_data=True,
account_passwords={"*": "test-password", "alice": "alice-pw"},
)
Credentials
Use either a user login or a script API key (not both):
- User login:
SHOTGUN_SERVER,SHOTGUN_LOGIN,SHOTGUN_PASSWORD - Script key:
SHOTGUN_SERVER,SHOTGUN_SCRIPT_NAME,SHOTGUN_API_KEY
CLI flags (--server, --login, --password, --script-name, --api-key)
are also available, but environment variables are recommended so passwords don't
end up in your shell history.
Good to know
- New file only: The output path must not already exist. If cloning fails, no partial file is left behind.
- Clone files: File downloads are opt-in.
--download-filesordownload_files=Truestores up to 64 MiB per file in SQLite.--file-storage DIRorfile_storage=DIRstores bytes in a new or empty directory without a size limit. These choices cannot be combined. Failed downloads are reported as warnings and keep the original source URLs. - Permissions: Your account must be able to access both the standard Shotgun
API and the web schema endpoint (
page/reload_schema). Sites that enforce SSO or two-factor authentication may block password or script logins. The cloner also attempts to read both permission catalogs; it warns and leaves permission enforcement disabled if those endpoints are unavailable. Field-permission page summaries are cloned separately when available; failure warns without disabling the rules. - No redirects: Use the site's final URL. Redirects are rejected so credentials aren't forwarded elsewhere.
- Selected entity types:
--all-dataand--entity-type(orall_dataandentity_typesin Python) cannot be combined. When copying selected types, links to uncopied records are dropped, and connections between copied types are included automatically. - What's inside the database: The SQLite file has one table per entity type,
plus internal tables for schema metadata, workday calendars, retired records,
and relationships. This is
fake-sg's own local format, not an exact copy of Shotgun's internal database. - Account passwords: Shotgun never returns real passwords or script keys,
so copied users and scripts have none and can't log in to a server started
with authentication. Use
--account-password ACCOUNT=PASSWORD(repeatable) oraccount_passwords={...}to store salted hashes of replacement passwords.ACCOUNTis aHumanUserlogin (case-insensitive) orApiUserscript name;*covers every copied account, and named accounts take precedence. Names that match no copied account produce a warning. - Keep clones private: Cloned databases can contain real project data, accounts, and site settings. Store them safely and never commit them to git.
Site permissions
fake-sg enforces a cloned site's permission roles ("permission groups") for the
caller of each request, like the real server: entity, field, value-specific,
and conditional rules for reads, creates, updates, and retirement, assigned
projects, and the advanced rules that affect the API, such as sudo. The
exceptions are listed in COMPATIBILITY.md.
- Clone them. Every clone copies both permission catalogs (people and
scripts), including the default templates, when the cloning account can
read the permission pages. Otherwise cloning warns and permissions are not
enforced. Callers must exist as records with a role, so use
--all-data, or includeHumanUser,ApiUser, andPermissionRuleSetwhen selecting entity types. - Use them. Permissions are enforced as soon as the server starts from a
clone with catalogs. Connect as a copied user or script. Any password works
unless you start the server with
authentication=Trueand give accounts passwords (account_passwordswhen cloning, or through the API). - Edit them. Use the same web endpoints as the site's permission pages,
with a session cookie from
get_session_token()for a caller whose role allowsset_permissions(such asadmin). Edits apply to the next request. The endpoints and their change formats are documented in UNOFFICIAL_APIS.md.
import json
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from shotgun_api3 import Shotgun
url = f"http://127.0.0.1:{port}"
admin = Shotgun(url, login="admin.user", password="any") # A copied user with the admin role
changes = [{"permission_rule_set_code": "artist", "rule_type": "see", "entity_type": "Asset", "allow": False}]
request = Request(f"{url}/page/set_permissions", data=urlencode({"permission_changes": json.dumps(changes)}).encode())
request.add_header("Cookie", f"_session_id={admin.get_session_token()}")
urlopen(request) # Artists can no longer read Assets.
/permissions/new_group copies a role, and /page/rename_permission_group,
/permissions/reset_group, /page/retire_permission_group, and
/page/delete_permission_rule manage roles and rules.
/permissions/data/HumanUser returns every role and its rules.
Editor support
The Python package includes type hints and docstrings for autocomplete and hover
help (for example, in VS Code with Pylance). Select this project's .venv
environment in your editor to enable them.
Development & testing
Run the standard checks:
cargo fmt --check
cargo test
cargo clippy --all-targets -- -D warnings
uv run pytest python_tests
After changing Rust code, run uv sync to rebuild the Python extension (type
stubs are regenerated automatically during builds). To force a rebuild:
uv sync --reinstall-package fake-sg
Python builds also compile the fake-sg binary and stage it in the ignored
fake_sg.data/scripts directory, which places it in the wheel's scripts.
Continuous integration and releases
.github/workflows/ci.yml runs formatting, all three clippy configurations,
cargo test, and pytest on Linux, macOS, and Windows for every pull request and
every push to main.
Pushing a tag such as v1.0.0 runs .github/workflows/release.yml. The
version is never bumped in source control: Cargo.toml and Cargo.lock stay
at 0.0.0, and the workflow stamps the tag's version into them with
.github/scripts/set_version.py before building (the Python package reads its
version from Cargo.toml). The workflow reruns CI, builds abi3 wheels (Python 3.10+) and standalone CLI
archives for every supported platform, smoke-tests each wheel's import and
fake-sg command, publishes the wheels and sdist to PyPI, and then creates a
GitHub release listing every wheel and binary with SHA-256 checksums. Tags with
a suffix such as v1.0.0-rc.1 become GitHub prereleases. Run the workflow
manually to build everything without publishing.
PyPI publishing uses trusted publishing: configure the fake-sg project on
PyPI to trust this repository's release.yml workflow and pypi environment.
Capturing reference queries from a real site
scripts/capture_shotgun_queries.py seeds a test site with synthetic records,
runs a suite of queries and updates against real Shotgun, and saves the results
to python_tests/test_data/shotgun_queries.pkl for compatibility testing.
Set your Shotgun credentials in your environment (or an ignored .env file),
then run:
uv run --script scripts/capture_shotgun_queries.py
uv sync
uv run pytest python_tests
To recapture standalone sections such as activity_queries,
navigation_queries, export_page_queries, authentication_queries,
permission_queries, subscription_queries, note_mutations, or entity_mutations, keeping the rest
of the existing fixture, pass --section once for each:
uv run --script scripts/capture_shotgun_queries.py --section task_dependency_mutations
- Use a disposable test site only: The script creates new test projects and adds custom fields to your site's schema.
- Do not load untrusted pickle files: Python pickles can execute arbitrary code. Only load this project's tracked fixture.
Metadata
Release files for fake-sg 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fake_sg-0.1.0.tar.gz | 1.3 MB | With provenance | Details for fake_sg-0.1.0.tar.gz |
Built distributions (wheels)
Total release size: 114.2 MB
Release files / fake_sg-0.1.0.tar.gz
| Download URL | fake_sg-0.1.0.tar.gz |
|---|---|
| Size | 1.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ec688a21b5e07d007714becca702e4c9463f719f13f39dc9d00ed1de99a0dc5
|
|
BLAKE2b-256 checksum How to use checksums |
405198c9cdc666b19738a233d067236de30e964dc3755c7d267c218cac6be0c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / fake_sg-0.1.0-cp310-abi3-win_arm64.whl
| Download URL | fake_sg-0.1.0-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 12.4 MB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2597d7ee055efbc27fb3cb59f95aeef5052e5344849c02011cf1f84ab9923664
|
|
BLAKE2b-256 checksum How to use checksums |
2441e0dd53e6a8c44256d32ca7a7b5aa727c19eceeb854b727c150399bc7a824
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / fake_sg-0.1.0-cp310-abi3-win_amd64.whl
| Download URL | fake_sg-0.1.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 13.1 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
02e462cf2dbf54c79b714f5cb491442a968dcb8270fdb93a39067ef5944ec97e
|
|
BLAKE2b-256 checksum How to use checksums |
2e3a4a8ef451e169dcaa10c4f0a261b767a9fe99ecbedc5a07cabb8c94496a8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / fake_sg-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | fake_sg-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 15.4 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
9f9f17875df09b1ebac959c544d27e2e63cfc63c665dadb2c0d8cb1e91f35439
|
|
BLAKE2b-256 checksum How to use checksums |
1def75ff3e821fd5e72e9fcaf819dc7b31a313e976d3886fa81e5aaf58889ed5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / fake_sg-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | fake_sg-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 14.8 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
5fcc395748f767aa6cd15b0943e5756d0c5e1d9f3ee7e33fea2f50f7c4df596a
|
|
BLAKE2b-256 checksum How to use checksums |
f183a25bb10e49eb515558d80e8b338b20e9cbbb24437516c22bdaad5896f439
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / fake_sg-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | fake_sg-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 14.9 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
cec86abbdaa6897bb6dbff63d6473234360dce70bda15d94bc55bb7b5e4b0b41
|
|
BLAKE2b-256 checksum How to use checksums |
ca7fab7fc42f9e29bdfadc561aa8385b58a98f12b32527f72e1cebbd72993124
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / fake_sg-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | fake_sg-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 14.7 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
779cd5088e0ec36046eea5da8ab6857fc4e13be3439430cc1c814fb9f4851ed9
|
|
BLAKE2b-256 checksum How to use checksums |
5dc9545a56668c97449c11931f7b909153245285786efd6e75d3a94c3a7c023e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / fake_sg-0.1.0-cp310-abi3-macosx_11_0_x86_64.whl
| Download URL | fake_sg-0.1.0-cp310-abi3-macosx_11_0_x86_64.whl |
|---|---|
| Size | 14.1 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
2056a0a1cd4cdeebdbc09da882f203a192e76962e0d475bdc2f2d199f28f25d7
|
|
BLAKE2b-256 checksum How to use checksums |
0f91a684e54bef1b3166a151cb0665e4b073177e394fa9e04bf5bd9034bbf546
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / fake_sg-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | fake_sg-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 13.5 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8433562cc99537653da817b7a84329fe5388a363f48d1c63db2efcd612b53637
|
|
BLAKE2b-256 checksum How to use checksums |
da03285467eea7affac9825c5f761cf79e6a1c251410c606bad82077fb5c75f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logSecurity for fake-sg 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 9 files in this release have been uploaded with provenance metadata.
Attestation for fake_sg-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.