Skip to main content

Async Python client for Stash GraphQL API

Reason this release was yanked:

Removing betas for versions with public releases

Project description

stash-graphql-client

PyPI version Python 3.12+ License: AGPL-3.0 codecov

Async Python client for Stash GraphQL API.

Features

  • Async-first: Built with gql + HTTPXAsyncTransport + WebsocketsTransport
  • Pydantic types: All Stash GraphQL schema objects as Pydantic models
  • Full CRUD: Operations for all entity types (Scene, Gallery, Performer, Studio, Tag, etc.)
  • Job management: Metadata scanning, generation, and job status tracking
  • Subscriptions: GraphQL subscription support for real-time updates

Installation

From PyPI (Recommended)

pip install stash-graphql-client

With Poetry

poetry add stash-graphql-client

From Source

git clone https://github.com/Jakan-Kink/stash-graphql-client.git
cd stash-graphql-client
poetry install

Requirements

  • Python 3.12+
  • Poetry for development

Quick Start

from stash_graphql_client import StashClient, StashContext

# Using context manager (recommended)
async with StashContext(conn={
    "Host": "localhost",
    "Port": 9999,
    "ApiKey": "your-api-key",  # Optional
}) as client:
    # Find all studios
    result = await client.find_studios()
    print(f"Found {result.count} studios")

    # Create a new tag
    tag = await client.create_tag(name="My Tag")
    print(f"Created tag: {tag.name}")

# Or manual lifecycle management
context = StashContext(conn={"Host": "localhost", "Port": 9999})
client = await context.get_client()
try:
    scenes = await client.find_scenes()
finally:
    await context.close()

Connection Options

conn = {
    "Scheme": "http",      # or "https"
    "Host": "localhost",   # Stash server host
    "Port": 9999,          # Stash server port
    "ApiKey": "...",       # Optional API key
}

Available Operations

Scenes

  • find_scenes(), find_scene(id), create_scene(), update_scene(), destroy_scene()

Galleries

  • find_galleries(), find_gallery(id), create_gallery(), update_gallery(), destroy_gallery()

Performers

  • find_performers(), find_performer(id), create_performer(), update_performer(), destroy_performer()

Studios

  • find_studios(), find_studio(id), create_studio(), update_studio(), destroy_studio()

Tags

  • find_tags(), find_tag(id), create_tag(), update_tag(), destroy_tag()

Metadata Operations

  • metadata_scan() - Scan for new media
  • metadata_generate() - Generate thumbnails, previews, etc.
  • find_job(), wait_for_job() - Job status tracking

Fuzzy Date Support (Stash v0.30.0+)

Stash v0.30.0 introduced support for partial dates (year-only or year-month formats) in addition to full dates. This client includes utilities to work with these "fuzzy" dates:

from stash_graphql_client.types import (
    FuzzyDate,
    validate_fuzzy_date,
    normalize_date,
    DatePrecision,
)

# Validate date formats
validate_fuzzy_date("2024")        # True - year only
validate_fuzzy_date("2024-03")     # True - year and month
validate_fuzzy_date("2024-03-15")  # True - full date
validate_fuzzy_date("2024-3")      # False - invalid format

# Create fuzzy dates
date = FuzzyDate("2024-03")
print(date.precision)  # DatePrecision.MONTH
print(date.to_datetime())  # datetime(2024, 3, 1)

# Normalize dates to different precisions
normalize_date("2024-03-15", "year")   # "2024"
normalize_date("2024-03-15", "month")  # "2024-03"
normalize_date("2024", "day")          # "2024-01-01"

# Use in performer/scene data
performer_data = {
    "name": "John Doe",
    "birthdate": "1990",  # Year-only birthdate
}
await client.create_performer(**performer_data)

scene_data = {
    "date": "2024-03",  # Month precision
}

Supported date formats:

  • YYYY - Year precision (e.g., "2024")
  • YYYY-MM - Month precision (e.g., "2024-03")
  • YYYY-MM-DD - Day precision (e.g., "2024-03-15")

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0-or-later).

See LICENSE for the full license text.

This license ensures:

  • ✅ Open source code sharing
  • ✅ Network use requires source disclosure
  • ✅ Compatible with Stash (also AGPL-3.0)
  • ✅ Derivative works must also be AGPL-3.0

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stash_graphql_client-0.5.0b7.tar.gz (177.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stash_graphql_client-0.5.0b7-py3-none-any.whl (221.2 kB view details)

Uploaded Python 3

File details

Details for the file stash_graphql_client-0.5.0b7.tar.gz.

File metadata

  • Download URL: stash_graphql_client-0.5.0b7.tar.gz
  • Upload date:
  • Size: 177.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stash_graphql_client-0.5.0b7.tar.gz
Algorithm Hash digest
SHA256 1f00930cdc6a45ffaeacfe0247cf54940c88997d94c60a1bc9ceb55c510915dc
MD5 905ea61ccc11356883b3735eee934aeb
BLAKE2b-256 0421e055f3874ee8513ab5262f0b99f65ee063f5cb180c58a326a92344b6b222

See more details on using hashes here.

Provenance

The following attestation bundles were made for stash_graphql_client-0.5.0b7.tar.gz:

Publisher: publish.yml on Jakan-Kink/stash-graphql-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stash_graphql_client-0.5.0b7-py3-none-any.whl.

File metadata

File hashes

Hashes for stash_graphql_client-0.5.0b7-py3-none-any.whl
Algorithm Hash digest
SHA256 193e05a04ba7442b8507f02d349442f5d490aae5abd69ec6cc453475dd849fb4
MD5 8b2d04715f6f9d89afc23a0e5508d462
BLAKE2b-256 23dec16d540f1953a899dc6a1613a851b44b33e2e11cdfc7e72bdd3fd3029232

See more details on using hashes here.

Provenance

The following attestation bundles were made for stash_graphql_client-0.5.0b7-py3-none-any.whl:

Publisher: publish.yml on Jakan-Kink/stash-graphql-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page