Metadata-Version: 2.4
Name: openaitrans
Version: 0.1.0
Summary: A powerful AI-based text translator using ChatGPT API
Home-page: https://github.com/amir3digh/openaitrans
Author: Amirhossein Sedigh
Author-email: amirhosseinseddigh@gmail.com
License: MIT
Keywords: translation,openai,chatgpt,language,nlp
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openai>=1.0.0
Requires-Dist: python-dotenv>=0.19.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: tiktoken>=0.3.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Dynamic: author-email
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# OpenAI Translator

A powerful AI-based text translator using ChatGPT API. This package provides an easy-to-use interface for translating text between different languages while preserving formatting and structure.

## Features

- Automatic language detection
- Support for multiple languages
- Preserves text formatting (Markdown, HTML, JSON, etc.)
- Streaming translation support
- Token usage tracking
- Configurable formality level
- Easy-to-use Python interface

## Installation

```bash
pip install openaitrans
```

## Usage

First, set up your OpenAI API key in your environment:

```bash
export OPENAI_API_KEY='your-api-key-here'
```

Or create a `.env` file in your project root:

```
OPENAI_API_KEY=your-api-key-here
```

### Basic Usage

```python
from openaitrans import translator

# Simple translation (auto-detect source language to Persian)
result = translator.translate("Hello, how are you?")
print(result.result)

# Specify source and target languages
result = translator.translate(
    "Hello, how are you?",
    t_from="en",
    t_to="fr"
)
print(result.result)

# Streaming translation
for chunk in translator.stream_translate():
    print(chunk)
```

### Advanced Usage

```python
from openaitrans import Translator

# Create a custom translator instance with specific settings
custom_translator = Translator(
    model="gpt-4",
    temperature=0.7,
    max_tokens=1000
)

# Translate with specific formatting
result = custom_translator.translate(
    "Hello, how are you?",
    t_from="en",
    t_to="fr",
    text_format="markdown"
)

# Get token usage information
print(custom_translator.token_usage)
```

## API Reference

### `Translator` Class

The main class for translation operations. Use this when you need custom settings.

#### Methods

- `translate(t_text, model="gpt-4o-mini", t_to=None, t_from=None)`: Translate text
- `stream_translate()`: Stream translation results
- `count_tokens()`: Get token usage information

#### Parameters

- `t_text`: Text to translate
- `model`: OpenAI model to use (default: "gpt-4o-mini")
- `t_to`: Target language code
- `t_from`: Source language code

### Default Instance

The package provides a default `translator` instance for quick and easy use:

```python
from openaitrans import translator

# Use the default instance
result = translator.translate("Hello, how are you?")
```

## License

This project is licensed under the MIT License - see the LICENSE file for details.

## Contributing

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