Skip to main content

Python SDK for Segmind API

Project description

Segmind Python SDK

A Python client library for interacting with Segmind APIs, providing easy access to model inference, PixelFlows, webhooks, file uploads, and more.

Installation

pip install segmind

export SEGMIND_API_KEY="your_api_key_here"

Quick Start

import segmind

# Generate an image
response = segmind.run(
    "seedream-v3-text-to-image",
    prompt="A beautiful sunset over mountains",
    aspect_ratio="16:9"
)

# Save the image
with open("sunset2.jpg", "wb") as f:
    f.write(response.content)

Core Components

  • SegmindClient: Main client for API interactions
  • PixelFlows: Workflow execution and management
  • Webhooks: Webhook configuration and monitoring
  • Files: Media file upload handling
  • Generations: Usage analytics and history
  • Models: Model discovery and information

Supported Media Formats

Images: png, jpg, jpeg, gif, bmp, webp, svg, ico, tif, tiff, jfif, pjp, apng, svgz, heif, heic, xbm

Audio: mp3, aiff, wma, au

Video: mp4, avi, mov, mkv, wmv, flv, webm, mpeg, mpg

Examples

Text to Image

import segmind

response = segmind.run(
    "seedream-v3-text-to-image",
    prompt="A cyberpunk cityscape at night",
    aspect_ratio="16:9"
)

with open("image.jpg", "wb") as f:
    f.write(response.content)

PixelFlows

import segmind

result = segmind.pixelflows.run(
    workflow_id="your-workflow-id",
    data={"prompt": "Generate an infographic"},
    poll=True
)

File Upload

import segmind

# Upload a file to Segmind Storage
result = segmind.files.upload("path/to/image.png")
print(result["file_urls"][0])
# https://images.segmind.com/assets/...

# Batch upload multiple files
result = segmind.files.upload(["image1.png", "image2.jpg"])
for url in result["file_urls"]:
    print(url)

Webhooks

import segmind

# Add a webhook
segmind.webhooks.add("https://your-endpoint.com", ["PIXELFLOW"])

# Get all webhooks
webhooks = segmind.webhooks.get()

Finetuning

from segmind import SegmindClient

client = SegmindClient()

# Get a presigned URL to upload your dataset (.zip)
upload = client.finetune.upload_presigned_url(name="my-dataset.zip")
# upload["presigned_url"] can be used with a PUT request to S3

# Submit a fine-tune request
job = client.finetune.submit(
    name="flux-job-1",
    data_source_path=upload["s3_url"],  # or any public zip URL
    instance_prompt="1MAN, running in brown suit",
    trigger_word="1MAN",
    base_model="FLUX",
    train_type="LORA",
    machine_type="NVIDIA_A100_40GB",
    theme="FLUX",
    segmind_public=False,
    advance_parameters={
        "steps": 1000,
        "batch_size": 2,
        "learning_rate": 4e-4,
    },
)

# Get details
details = client.finetune.details(request_id=job["finetune_id"])

# List all
all_jobs = client.finetune.list()

# Update access (public/private)
client.finetune.access_update(request_id=job["finetune_id"], segmind_public=True)

# Download model file (returns a temporary URL string)
download_url = client.finetune.file_download(cloud_storage_url=details["finetune"]["cloud_storage_url"])

Documentation

For detailed examples and API reference, see examples.md.

Public API Playground (Swagger UI): open docs/swagger.html after building docs, or serve docs/ statically. It loads the spec at docs/_static/openapi/segmind-sdk.yaml and supports the Authorize flow with x-api-key.

Run this to serve the documentation:

cd docs && python3 -m http.server 8000

Then open http://localhost:8000 in your browser.

Requirements

  • Python 3.8+
  • httpx
  • typing-extensions (for Python < 3.10)

Error Handling

The SDK provides comprehensive error handling with detailed error messages:

import segmind
from segmind.exceptions import SegmindError

try:
    response = segmind.run("invalid-model", prompt="test")
except SegmindError as e:
    print(f"API Error: {e.detail}")
    print(f"Status Code: {e.status}")

Development

Setup Development Environment

  1. Clone the repository:

    git clone https://github.com/segmind/segmind-python.git
    cd segmind-python
    
  2. Install development dependencies:

    pip install -e ".[test,dev]"
    
  3. Install pre-commit hooks:

    pre-commit install
    

Running Tests

# Run all tests
make test

# Run with coverage
make test-coverage

# Run verbose
make test-verbose

Linting and Formatting

# Run all pre-commit checks
make lint

# Or run pre-commit directly
pre-commit run --all-files

Building the Package

# Build distribution packages
make build

# Build and check with twine
make build-check

Releasing

For information on creating releases and publishing to PyPI, see RELEASING.md.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests: make test
  5. Ensure code quality: pre-commit run --all-files
  6. Submit a pull request

See CONTRIBUTING.md for detailed contribution guidelines.

License

This project is licensed under the MIT License.

Support

For support and questions:

Project details


Download files

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

Source Distribution

segmind-1.0.1.tar.gz (71.9 kB view details)

Uploaded Source

Built Distribution

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

segmind-1.0.1-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file segmind-1.0.1.tar.gz.

File metadata

  • Download URL: segmind-1.0.1.tar.gz
  • Upload date:
  • Size: 71.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for segmind-1.0.1.tar.gz
Algorithm Hash digest
SHA256 24872f1b97cd7a45b2493a9b6b4bd511ba5bdd017d47540c680efff9ca30d724
MD5 377699f99ca72879e66f541447102cae
BLAKE2b-256 4f48344c3a4e55fab3794bf92fb09e44f0a942a74bcf420fd40ba348168e9a49

See more details on using hashes here.

Provenance

The following attestation bundles were made for segmind-1.0.1.tar.gz:

Publisher: publish.yml on segmind/segmind-python

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

File details

Details for the file segmind-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: segmind-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for segmind-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b3097a99959115f70a6d6f12b460d8c4d7ad3792d5fc57263a02383a1badebd8
MD5 c3c9de7e1561230160d440e86e1f8bdd
BLAKE2b-256 b89ce940e0ac24f1fdd9fba5b9c3650a9b87667ab815e67c28154f07e9b47e75

See more details on using hashes here.

Provenance

The following attestation bundles were made for segmind-1.0.1-py3-none-any.whl:

Publisher: publish.yml on segmind/segmind-python

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