dynaspark


Namedynaspark JSON
Version 1.2.2.3 PyPI version JSON
download
home_pagehttps://github.com/Th3-C0der/DynaSpark
SummaryA Python client for the DynaSpark API - Free AI text generation, text-to-speech, and image generation
upload_time2025-07-31 16:36:11
maintainerNone
docs_urlNone
authorTh3-C0der
requires_python>=3.6
licenseMIT
keywords ai text-generation image-generation audio-generation api dynaspark
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # DynaSpark Python Client 

<div align="center">

[![PyPI version](https://badge.fury.io/py/dynaspark.svg)](https://badge.fury.io/py/dynaspark)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/)

A powerful, free Python client for the DynaSpark API - No API key required! 

</div>

## Features

| Feature | Description |
|---------|-------------|
| **Free Usage** | No API key required - uses free key by default |
| **Text Generation** | Generate text responses with customizable parameters including temperature, top_p, and more |
| **Image Generation** | Create high-quality images with various models, resolutions, and watermark options |
| **Audio Generation** | Convert text to speech with multiple voice options |
| **OpenAI Compatible** | Use as a drop-in replacement for OpenAI API |
| **Streaming Support** | Get responses as they're generated with real-time streaming |
| **Rate Limiting** | Built-in rate limit handling with usage statistics |
| **Error Handling** | Comprehensive error handling with specific exception types |
| **Easy to Use** | Simple and intuitive Python interface |
| **Secure** | Built-in validation and privacy controls |

## Installation

```bash
pip install dynaspark
```

> **Note:** Requires Python 3.7 or higher.

## Authentication

No API key is required to get started - the client uses a free key by default. However, you can specify your own API key if needed:

```python
from dynaspark import DynaSpark

# Use with default free API key
ds = DynaSpark()

# Or specify your own API key
ds = DynaSpark(api_key="your_api_key")
```

## Advanced Text Generation

Generate text with fine-grained control over the output:

```python
# Advanced text generation with various parameters
response = ds.generate_response(
    "Write a technical article about AI",
    model="mistral",
    temperature=0.8,
    top_p=0.9,
    presence_penalty=0.6,
    frequency_penalty=0.6,
    system="You are a technical writer with expertise in AI",
    stream=True,  # Enable streaming
    private=True,  # Keep generation private
    seed=42,       # For reproducible results
    json=False     # Return as JSON
)
```

## Advanced Image Generation

Create custom images with various options:

```python
# Generate high-quality images with custom settings
image_url = ds.generate_image(
    "A futuristic city with flying cars and neon lights",
    width=1024,      # Image width (64-2048)
    height=768,      # Image height (64-2048)
    model="flux",    # Options: flux, turbo, gptimage
    nologo=True,     # Exclude watermark
    wm="MyApp"       # Custom watermark text
)
```

## Advanced Audio Generation

Convert text to speech with multiple voice options:

```python
# Generate speech with different voices
voices = ["alloy", "echo", "nova", "shimmer", "fable", "onyx"]
for i, voice in enumerate(voices):
    audio_data = ds.generate_audio_response(
        f"This is the {voice} voice",
        voice=voice
    )
    ds.save_audio(audio_data, f"{voice}_demo.mp3")
```

## Quick Start

### Text Generation

```python
from dynaspark import DynaSpark

ds = DynaSpark()

# Basic text generation
response = ds.generate_response("What is artificial intelligence?")
print(response.get('response', ''))

# Advanced usage with parameters
response = ds.generate_response(
    "Write a poem about technology",
    model="mistral",          # Model to use
    temperature=0.8,         # Controls randomness (0.0 to 3.0)
    top_p=0.9,              # Controls diversity (0.0 to 1.0)
    presence_penalty=0.6,    # Penalizes repeated tokens (-2.0 to 2.0)
    frequency_penalty=0.6,   # Penalizes frequent tokens (-2.0 to 2.0)
    json=True,              # Return JSON response
    system="You are a poet", # Custom system prompt
    stream=False,           # Stream the response
    private=False,          # Keep generation private
    seed=42                 # For reproducible results
)
```

### Image Generation

```python
# Generate an image
image_url = ds.generate_image("A beautiful sunset over mountains")

# Advanced image generation with parameters
image_url = ds.generate_image(
    "A futuristic city with flying cars",
    width=1024,         # Image width (64-2048)
    height=768,         # Image height (64-2048)
    model="flux",       # Model to use (flux/turbo/gptimage)
    nologo=True,        # Exclude watermark
    wm="DynaSpark"      # Custom watermark text
)
print(f"Generated image: {image_url}")
```

### Audio Generation

```python
# Generate audio from text
audio_data = ds.generate_audio_response("Hello, this is a test!")

# Save audio to file
ds.save_audio(audio_data, "response.mp3")

# With different voice
audio_data = ds.generate_audio_response(
    "This is a test with a different voice.",
    voice="nova"  # Options: alloy, echo, fable, onyx, nova, shimmer
)
```

## OpenAI Compatibility

DynaSpark is compatible with the OpenAI Python package! Simply set the base URL to the DynaSpark OpenAI-compatible endpoint:

```python
from openai import OpenAI

# Configure OpenAI client
client = OpenAI(
    base_url="https://dynaspark.onrender.com/openai",
    api_key="any_string_here",  # API key is not required but required by the client
)

# Use it like regular OpenAI API
completion = client.chat.completions.create(
    model="openai",
    messages=[
        {"role": "user", "content": "What is the meaning of life?"}
    ]
)

print(completion.choices[0].message.content)
```

## Error Handling

The client provides custom exceptions for better error handling:

```python
from dynaspark import DynaSpark, DynaSparkError

ds = DynaSpark()

try:
    response = ds.generate_response("Hello")
    print(response.get('response', ''))
except DynaSparkError as e:
    print(f"API Error: {e}")
except ValueError as e:
    print(f"Invalid Parameter: {e}")
except Exception as e:
    print(f"Unexpected Error: {e}")
```

### Common Exceptions

| Exception | Description |
|-----------|-------------|
| `DynaSparkError` | Base exception for API errors |
| `RateLimitError` | Raised when rate limit is exceeded |
| `AuthenticationError` | Raised for authentication issues |
| `ValidationError` | Raised for invalid parameters |

## Rate Limiting

The API implements rate limiting to ensure fair usage. The client provides information about your current usage:

```python
# Get rate limit information
rate_limit = ds.get_rate_limit()
print(f"Remaining requests: {rate_limit.remaining}")
print(f"Reset time: {rate_limit.reset_time}")
```

## Streaming Responses

For long text generations, you can use streaming to get responses as they're generated:

```python
# Stream a response
for chunk in ds.generate_response(
    "Write a long story about artificial intelligence",
    stream=True
):
    print(chunk, end='', flush=True)
```

## Examples

### Text Generation Examples

```python
# Chat completion
response = ds.generate_response(
    "You are a helpful assistant. Explain quantum computing.",
    model="mistral",
    temperature=0.7
)
print(response['response'])

# Code generation
response = ds.generate_response(
    "Write a Python function to sort a list of dictionaries by a key",
    model="qwen-coder",
    temperature=0.2
)
print(response['response'])
```

### Image Generation Examples

```python
# Basic image generation
image_url = ds.generate_image(
    "A cute cat playing with yarn",
    model="flux"
)

# High-resolution image
image_url = ds.generate_image(
    "A detailed landscape of mountains at sunset",
    width=1024,
    height=768,
    model="turbo"
)
```

### Audio Generation Examples

```python
# Basic audio generation
audio_data = ds.generate_audio_response(
    "Welcome to DynaSpark! This is a test of the audio generation.",
    voice="alloy"
)
ds.save_audio(audio_data, "welcome.mp3")

# Multiple voices
voices = ["alloy", "echo", "nova"]
for i, voice in enumerate(voices):
    audio_data = ds.generate_audio_response(
        f"This is voice {voice}",
        voice=voice
    )
    ds.save_audio(audio_data, f"voice_{i}.mp3")
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Support

For support, please open an issue in the GitHub repository.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Th3-C0der/DynaSpark",
    "name": "dynaspark",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "ai, text-generation, image-generation, audio-generation, api, dynaspark",
    "author": "Th3-C0der",
    "author_email": "dvp.ai.ml@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c4/0c/230d6001bed0ab05bb0374804845aa312186258553524cc6f3e92469c65a/dynaspark-1.2.2.3.tar.gz",
    "platform": null,
    "description": "# DynaSpark Python Client \r\n\r\n<div align=\"center\">\r\n\r\n[![PyPI version](https://badge.fury.io/py/dynaspark.svg)](https://badge.fury.io/py/dynaspark)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/)\r\n\r\nA powerful, free Python client for the DynaSpark API - No API key required! \r\n\r\n</div>\r\n\r\n## Features\r\n\r\n| Feature | Description |\r\n|---------|-------------|\r\n| **Free Usage** | No API key required - uses free key by default |\r\n| **Text Generation** | Generate text responses with customizable parameters including temperature, top_p, and more |\r\n| **Image Generation** | Create high-quality images with various models, resolutions, and watermark options |\r\n| **Audio Generation** | Convert text to speech with multiple voice options |\r\n| **OpenAI Compatible** | Use as a drop-in replacement for OpenAI API |\r\n| **Streaming Support** | Get responses as they're generated with real-time streaming |\r\n| **Rate Limiting** | Built-in rate limit handling with usage statistics |\r\n| **Error Handling** | Comprehensive error handling with specific exception types |\r\n| **Easy to Use** | Simple and intuitive Python interface |\r\n| **Secure** | Built-in validation and privacy controls |\r\n\r\n## Installation\r\n\r\n```bash\r\npip install dynaspark\r\n```\r\n\r\n> **Note:** Requires Python 3.7 or higher.\r\n\r\n## Authentication\r\n\r\nNo API key is required to get started - the client uses a free key by default. However, you can specify your own API key if needed:\r\n\r\n```python\r\nfrom dynaspark import DynaSpark\r\n\r\n# Use with default free API key\r\nds = DynaSpark()\r\n\r\n# Or specify your own API key\r\nds = DynaSpark(api_key=\"your_api_key\")\r\n```\r\n\r\n## Advanced Text Generation\r\n\r\nGenerate text with fine-grained control over the output:\r\n\r\n```python\r\n# Advanced text generation with various parameters\r\nresponse = ds.generate_response(\r\n    \"Write a technical article about AI\",\r\n    model=\"mistral\",\r\n    temperature=0.8,\r\n    top_p=0.9,\r\n    presence_penalty=0.6,\r\n    frequency_penalty=0.6,\r\n    system=\"You are a technical writer with expertise in AI\",\r\n    stream=True,  # Enable streaming\r\n    private=True,  # Keep generation private\r\n    seed=42,       # For reproducible results\r\n    json=False     # Return as JSON\r\n)\r\n```\r\n\r\n## Advanced Image Generation\r\n\r\nCreate custom images with various options:\r\n\r\n```python\r\n# Generate high-quality images with custom settings\r\nimage_url = ds.generate_image(\r\n    \"A futuristic city with flying cars and neon lights\",\r\n    width=1024,      # Image width (64-2048)\r\n    height=768,      # Image height (64-2048)\r\n    model=\"flux\",    # Options: flux, turbo, gptimage\r\n    nologo=True,     # Exclude watermark\r\n    wm=\"MyApp\"       # Custom watermark text\r\n)\r\n```\r\n\r\n## Advanced Audio Generation\r\n\r\nConvert text to speech with multiple voice options:\r\n\r\n```python\r\n# Generate speech with different voices\r\nvoices = [\"alloy\", \"echo\", \"nova\", \"shimmer\", \"fable\", \"onyx\"]\r\nfor i, voice in enumerate(voices):\r\n    audio_data = ds.generate_audio_response(\r\n        f\"This is the {voice} voice\",\r\n        voice=voice\r\n    )\r\n    ds.save_audio(audio_data, f\"{voice}_demo.mp3\")\r\n```\r\n\r\n## Quick Start\r\n\r\n### Text Generation\r\n\r\n```python\r\nfrom dynaspark import DynaSpark\r\n\r\nds = DynaSpark()\r\n\r\n# Basic text generation\r\nresponse = ds.generate_response(\"What is artificial intelligence?\")\r\nprint(response.get('response', ''))\r\n\r\n# Advanced usage with parameters\r\nresponse = ds.generate_response(\r\n    \"Write a poem about technology\",\r\n    model=\"mistral\",          # Model to use\r\n    temperature=0.8,         # Controls randomness (0.0 to 3.0)\r\n    top_p=0.9,              # Controls diversity (0.0 to 1.0)\r\n    presence_penalty=0.6,    # Penalizes repeated tokens (-2.0 to 2.0)\r\n    frequency_penalty=0.6,   # Penalizes frequent tokens (-2.0 to 2.0)\r\n    json=True,              # Return JSON response\r\n    system=\"You are a poet\", # Custom system prompt\r\n    stream=False,           # Stream the response\r\n    private=False,          # Keep generation private\r\n    seed=42                 # For reproducible results\r\n)\r\n```\r\n\r\n### Image Generation\r\n\r\n```python\r\n# Generate an image\r\nimage_url = ds.generate_image(\"A beautiful sunset over mountains\")\r\n\r\n# Advanced image generation with parameters\r\nimage_url = ds.generate_image(\r\n    \"A futuristic city with flying cars\",\r\n    width=1024,         # Image width (64-2048)\r\n    height=768,         # Image height (64-2048)\r\n    model=\"flux\",       # Model to use (flux/turbo/gptimage)\r\n    nologo=True,        # Exclude watermark\r\n    wm=\"DynaSpark\"      # Custom watermark text\r\n)\r\nprint(f\"Generated image: {image_url}\")\r\n```\r\n\r\n### Audio Generation\r\n\r\n```python\r\n# Generate audio from text\r\naudio_data = ds.generate_audio_response(\"Hello, this is a test!\")\r\n\r\n# Save audio to file\r\nds.save_audio(audio_data, \"response.mp3\")\r\n\r\n# With different voice\r\naudio_data = ds.generate_audio_response(\r\n    \"This is a test with a different voice.\",\r\n    voice=\"nova\"  # Options: alloy, echo, fable, onyx, nova, shimmer\r\n)\r\n```\r\n\r\n## OpenAI Compatibility\r\n\r\nDynaSpark is compatible with the OpenAI Python package! Simply set the base URL to the DynaSpark OpenAI-compatible endpoint:\r\n\r\n```python\r\nfrom openai import OpenAI\r\n\r\n# Configure OpenAI client\r\nclient = OpenAI(\r\n    base_url=\"https://dynaspark.onrender.com/openai\",\r\n    api_key=\"any_string_here\",  # API key is not required but required by the client\r\n)\r\n\r\n# Use it like regular OpenAI API\r\ncompletion = client.chat.completions.create(\r\n    model=\"openai\",\r\n    messages=[\r\n        {\"role\": \"user\", \"content\": \"What is the meaning of life?\"}\r\n    ]\r\n)\r\n\r\nprint(completion.choices[0].message.content)\r\n```\r\n\r\n## Error Handling\r\n\r\nThe client provides custom exceptions for better error handling:\r\n\r\n```python\r\nfrom dynaspark import DynaSpark, DynaSparkError\r\n\r\nds = DynaSpark()\r\n\r\ntry:\r\n    response = ds.generate_response(\"Hello\")\r\n    print(response.get('response', ''))\r\nexcept DynaSparkError as e:\r\n    print(f\"API Error: {e}\")\r\nexcept ValueError as e:\r\n    print(f\"Invalid Parameter: {e}\")\r\nexcept Exception as e:\r\n    print(f\"Unexpected Error: {e}\")\r\n```\r\n\r\n### Common Exceptions\r\n\r\n| Exception | Description |\r\n|-----------|-------------|\r\n| `DynaSparkError` | Base exception for API errors |\r\n| `RateLimitError` | Raised when rate limit is exceeded |\r\n| `AuthenticationError` | Raised for authentication issues |\r\n| `ValidationError` | Raised for invalid parameters |\r\n\r\n## Rate Limiting\r\n\r\nThe API implements rate limiting to ensure fair usage. The client provides information about your current usage:\r\n\r\n```python\r\n# Get rate limit information\r\nrate_limit = ds.get_rate_limit()\r\nprint(f\"Remaining requests: {rate_limit.remaining}\")\r\nprint(f\"Reset time: {rate_limit.reset_time}\")\r\n```\r\n\r\n## Streaming Responses\r\n\r\nFor long text generations, you can use streaming to get responses as they're generated:\r\n\r\n```python\r\n# Stream a response\r\nfor chunk in ds.generate_response(\r\n    \"Write a long story about artificial intelligence\",\r\n    stream=True\r\n):\r\n    print(chunk, end='', flush=True)\r\n```\r\n\r\n## Examples\r\n\r\n### Text Generation Examples\r\n\r\n```python\r\n# Chat completion\r\nresponse = ds.generate_response(\r\n    \"You are a helpful assistant. Explain quantum computing.\",\r\n    model=\"mistral\",\r\n    temperature=0.7\r\n)\r\nprint(response['response'])\r\n\r\n# Code generation\r\nresponse = ds.generate_response(\r\n    \"Write a Python function to sort a list of dictionaries by a key\",\r\n    model=\"qwen-coder\",\r\n    temperature=0.2\r\n)\r\nprint(response['response'])\r\n```\r\n\r\n### Image Generation Examples\r\n\r\n```python\r\n# Basic image generation\r\nimage_url = ds.generate_image(\r\n    \"A cute cat playing with yarn\",\r\n    model=\"flux\"\r\n)\r\n\r\n# High-resolution image\r\nimage_url = ds.generate_image(\r\n    \"A detailed landscape of mountains at sunset\",\r\n    width=1024,\r\n    height=768,\r\n    model=\"turbo\"\r\n)\r\n```\r\n\r\n### Audio Generation Examples\r\n\r\n```python\r\n# Basic audio generation\r\naudio_data = ds.generate_audio_response(\r\n    \"Welcome to DynaSpark! This is a test of the audio generation.\",\r\n    voice=\"alloy\"\r\n)\r\nds.save_audio(audio_data, \"welcome.mp3\")\r\n\r\n# Multiple voices\r\nvoices = [\"alloy\", \"echo\", \"nova\"]\r\nfor i, voice in enumerate(voices):\r\n    audio_data = ds.generate_audio_response(\r\n        f\"This is voice {voice}\",\r\n        voice=voice\r\n    )\r\n    ds.save_audio(audio_data, f\"voice_{i}.mp3\")\r\n```\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a Pull Request.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n\r\n## Support\r\n\r\nFor support, please open an issue in the GitHub repository.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python client for the DynaSpark API - Free AI text generation, text-to-speech, and image generation",
    "version": "1.2.2.3",
    "project_urls": {
        "Bug Tracker": "https://github.com/Th3-C0der/DynaSpark/issues",
        "Documentation": "https://github.com/Th3-C0der/DynaSpark#readme",
        "Homepage": "https://github.com/Th3-C0der/DynaSpark",
        "Source Code": "https://github.com/Th3-C0der/DynaSpark"
    },
    "split_keywords": [
        "ai",
        " text-generation",
        " image-generation",
        " audio-generation",
        " api",
        " dynaspark"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "077b82bd04788ab36f107684c3069bada9ed87644ad2396a04443fbd1976fbcb",
                "md5": "a5d5d78718da68dca7f73dc67f3d3886",
                "sha256": "9e9548f2e8e84e5b278dd8721ecf1f9bd4204c72f634764cb853bcfc5d723ca0"
            },
            "downloads": -1,
            "filename": "dynaspark-1.2.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a5d5d78718da68dca7f73dc67f3d3886",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7822,
            "upload_time": "2025-07-31T16:36:10",
            "upload_time_iso_8601": "2025-07-31T16:36:10.725531Z",
            "url": "https://files.pythonhosted.org/packages/07/7b/82bd04788ab36f107684c3069bada9ed87644ad2396a04443fbd1976fbcb/dynaspark-1.2.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c40c230d6001bed0ab05bb0374804845aa312186258553524cc6f3e92469c65a",
                "md5": "5930c19f9b898b30c799bce9bd0378e0",
                "sha256": "ca86fdb166cc1d247c524baaf59f03642ea01baab1de65f6ff63d60acb64df23"
            },
            "downloads": -1,
            "filename": "dynaspark-1.2.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "5930c19f9b898b30c799bce9bd0378e0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 9805,
            "upload_time": "2025-07-31T16:36:11",
            "upload_time_iso_8601": "2025-07-31T16:36:11.869511Z",
            "url": "https://files.pythonhosted.org/packages/c4/0c/230d6001bed0ab05bb0374804845aa312186258553524cc6f3e92469c65a/dynaspark-1.2.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-31 16:36:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Th3-C0der",
    "github_project": "DynaSpark",
    "github_not_found": true,
    "lcname": "dynaspark"
}
        
Elapsed time: 1.71379s