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.0b4.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.0b4-py3-none-any.whl (221.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stash_graphql_client-0.5.0b4.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.0b4.tar.gz
Algorithm Hash digest
SHA256 4cbc8d920b7931bf99e6402dc1f3f01b29f185c8068ab122b8cdf85eb2f36b25
MD5 29395e8552c481233db2cc1d632d6f8d
BLAKE2b-256 5decadcbed92a3cde7d4aebb2fd26364bcfcd906b8a90e4ff517495e9374480a

See more details on using hashes here.

Provenance

The following attestation bundles were made for stash_graphql_client-0.5.0b4.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.0b4-py3-none-any.whl.

File metadata

File hashes

Hashes for stash_graphql_client-0.5.0b4-py3-none-any.whl
Algorithm Hash digest
SHA256 515afffeb9276081114fa3dc23712c02b665d0dba0a0ce56583fddf9a28becb8
MD5 5882a2c2bffb11942ee8f99aa9256619
BLAKE2b-256 9f5c1cd69bbe7b161b199739cf753872e51cd5c245ed7efad74786c3d0f2c6cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for stash_graphql_client-0.5.0b4-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