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

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

# 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.

python3 -m http.server 8000

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-internal.git
    cd segmind-python-internal
    
  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.0.tar.gz (66.1 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.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: segmind-1.0.0.tar.gz
  • Upload date:
  • Size: 66.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for segmind-1.0.0.tar.gz
Algorithm Hash digest
SHA256 793e6342150c374880a137094488491d59f48a2d28da9442413bb2a94c9d7fbd
MD5 d937d29c1e4901267253fc64327995b8
BLAKE2b-256 a2eb25d46f0d410ae586e52ef849e4f9d42cdc21920afe875c42f0796b0749a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: segmind-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for segmind-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c6428f5c2e1283147eca20d87aeb837e27fd96a97f69ab491f284860168ca62
MD5 d7b577b613065bb79e405f16c50b2649
BLAKE2b-256 38425779b447f4c66c2d7136a92d53ddb2bd9cc49ef83e6ec3ddf82effd4851e

See more details on using hashes here.

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