bfloat


Namebfloat JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://github.com/bfloat-ai/python-sdk
SummaryA Python SDK for interacting with the bfloat.ai API
upload_time2024-11-05 03:04:06
maintainerNone
docs_urlNone
authorEdison Abahurire
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # BFloat.ai Python SDK

[![PyPI version](https://img.shields.io/pypi/v/bfloat.svg)](https://pypi.org/project/bfloat/)
[![Python](https://img.shields.io/pypi/pyversions/bfloat.svg)](https://www.python.org/)
[![Async Support](https://img.shields.io/badge/async-ready-green.svg)](https://docs.python.org/3/library/asyncio.html)

A powerful and intuitive Python SDK for interacting with the bfloat.ai API. Manage browser automation sessions with ease using modern async/await patterns.

## Features

- 🚀 Full type hinting support with dataclasses
- 💪 Async/await support using aiohttp
- 🛡️ Robust error handling
- 🔄 Complete session lifecycle management
- ⚙️ Flexible browser configuration
- 📘 Extensive documentation and examples

## Installation

```bash
# Using pip
pip install bfloat

# Using poetry
poetry add bfloat

# Using pipenv
pipenv install bfloat
```

## Quick Start

```python
from bfloat import BfloatSDK, DEFAULT_BROWSER_CONFIG
import asyncio

# Initialize the SDK
bfloat = BfloatSDK('your-api-key')

# Create and manage a session
async def example():
    try:
        # Create a new session
        session = await bfloat.create_session({
            'browser': DEFAULT_BROWSER_CONFIG,
            'lifetime': 3600,
            'keep_alive': True
        })

        print(f'Session created: {session.id}')
        print(f'Debug URL: {session.debug_info.ws_debugger_url}')

        # Stop the session when done
        await bfloat.stop_session(session.id)
    except Exception as error:
        print(f'Error: {error}')
    finally:
        await bfloat.close()

# Run the example
asyncio.run(example())
```

## API Reference

### Initialization

```python
bfloat = BfloatSDK(api_key: str, base_url: str = "https://api.bfloat.ai/v1")
```

### Methods

#### List Sessions
```python
sessions = await bfloat.list_sessions()
```

#### Get Session Details
```python
session = await bfloat.get_session(session_id: str)
```

#### Create Session
```python
session = await bfloat.create_session(config: SessionConfig)
```

#### Stop Session
```python
result = await bfloat.stop_session(session_id: str)
```

### Configuration

#### Browser Configuration
```python
@dataclass
class BrowserConfig:
    type: str
    settings: Optional[BrowserSettings] = None
    block_ads: Optional[bool] = None
    proxy: Optional[bool] = None

@dataclass
class BrowserSettings:
    os: Optional[List[str]] = None
    devices: Optional[List[str]] = None
    screen: Optional[Dict[str, int]] = None
    locales: Optional[List[str]] = None
```

#### Session Configuration
```python
@dataclass
class SessionConfig:
    browser: BrowserConfig
    lifetime: Optional[int] = None
    keep_alive: Optional[bool] = None
```

## Error Handling

The SDK provides a custom `BFloatError` class for error handling:

```python
try:
    session = await bfloat.create_session(config)
except BFloatError as error:
    print(f'Status: {error.status}')
    print(f'Message: {error.message}')
    print(f'Response: {error.response}')
```

## Complete Example

```python
from bfloat import BfloatSDK, BFloatError, DEFAULT_BROWSER_CONFIG, SessionConfig
import asyncio

async def run_browser_session():
    bfloat = BfloatSDK('your-api-key')

    try:
        # List existing sessions
        sessions = await bfloat.list_sessions()
        print(f'Active sessions: {len(sessions)}')

        # Create a new session
        config = SessionConfig(
            browser=DEFAULT_BROWSER_CONFIG,
            lifetime=3600
        )
        session = await bfloat.create_session(config)

        print(f'New session: {session.id}')
        print(f'Debug URL: {session.debug_info.ws_debugger_url}')

        # Get session details
        details = await bfloat.get_session(session.id)
        print(f'Session status: {details.status}')

        # Stop session
        await bfloat.stop_session(session.id)
        print('Session stopped successfully')

    except BFloatError as error:
        print(f'BFloat API error: {error}')
        print(f'Status: {error.status}')
    except Exception as error:
        print(f'Unexpected error: {error}')
    finally:
        await bfloat.close()

# Run the example
if __name__ == "__main__":
    asyncio.run(run_browser_session())
```

## Development

```bash
# Install dependencies
poetry install

# Run tests
pytest

# Build
poetry build

# Generate documentation
pdoc --html bfloat_sdk
```

## Contributing

We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

## License

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

## Support

- Documentation: [https://docs.bfloat.ai](https://docs.bfloat.ai)
- Issues: [GitHub Issues](https://github.com/bfloat-inc/python-sdk-python/issues)
- Email: support@bfloat.ai

## Security

If you discover a security vulnerability, please send an email to security@bfloat.ai. All security vulnerabilities will be promptly addressed.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bfloat-ai/python-sdk",
    "name": "bfloat",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Edison Abahurire",
    "author_email": "edison@bfloat.ai",
    "download_url": "https://files.pythonhosted.org/packages/cd/7a/550c0874aefb53867f2fb662ed75ede8284d52b81bcd27ada2e5ade1688b/bfloat-1.0.3.tar.gz",
    "platform": null,
    "description": "# BFloat.ai Python SDK\n\n[![PyPI version](https://img.shields.io/pypi/v/bfloat.svg)](https://pypi.org/project/bfloat/)\n[![Python](https://img.shields.io/pypi/pyversions/bfloat.svg)](https://www.python.org/)\n[![Async Support](https://img.shields.io/badge/async-ready-green.svg)](https://docs.python.org/3/library/asyncio.html)\n\nA powerful and intuitive Python SDK for interacting with the bfloat.ai API. Manage browser automation sessions with ease using modern async/await patterns.\n\n## Features\n\n- \ud83d\ude80 Full type hinting support with dataclasses\n- \ud83d\udcaa Async/await support using aiohttp\n- \ud83d\udee1\ufe0f Robust error handling\n- \ud83d\udd04 Complete session lifecycle management\n- \u2699\ufe0f Flexible browser configuration\n- \ud83d\udcd8 Extensive documentation and examples\n\n## Installation\n\n```bash\n# Using pip\npip install bfloat\n\n# Using poetry\npoetry add bfloat\n\n# Using pipenv\npipenv install bfloat\n```\n\n## Quick Start\n\n```python\nfrom bfloat import BfloatSDK, DEFAULT_BROWSER_CONFIG\nimport asyncio\n\n# Initialize the SDK\nbfloat = BfloatSDK('your-api-key')\n\n# Create and manage a session\nasync def example():\n    try:\n        # Create a new session\n        session = await bfloat.create_session({\n            'browser': DEFAULT_BROWSER_CONFIG,\n            'lifetime': 3600,\n            'keep_alive': True\n        })\n\n        print(f'Session created: {session.id}')\n        print(f'Debug URL: {session.debug_info.ws_debugger_url}')\n\n        # Stop the session when done\n        await bfloat.stop_session(session.id)\n    except Exception as error:\n        print(f'Error: {error}')\n    finally:\n        await bfloat.close()\n\n# Run the example\nasyncio.run(example())\n```\n\n## API Reference\n\n### Initialization\n\n```python\nbfloat = BfloatSDK(api_key: str, base_url: str = \"https://api.bfloat.ai/v1\")\n```\n\n### Methods\n\n#### List Sessions\n```python\nsessions = await bfloat.list_sessions()\n```\n\n#### Get Session Details\n```python\nsession = await bfloat.get_session(session_id: str)\n```\n\n#### Create Session\n```python\nsession = await bfloat.create_session(config: SessionConfig)\n```\n\n#### Stop Session\n```python\nresult = await bfloat.stop_session(session_id: str)\n```\n\n### Configuration\n\n#### Browser Configuration\n```python\n@dataclass\nclass BrowserConfig:\n    type: str\n    settings: Optional[BrowserSettings] = None\n    block_ads: Optional[bool] = None\n    proxy: Optional[bool] = None\n\n@dataclass\nclass BrowserSettings:\n    os: Optional[List[str]] = None\n    devices: Optional[List[str]] = None\n    screen: Optional[Dict[str, int]] = None\n    locales: Optional[List[str]] = None\n```\n\n#### Session Configuration\n```python\n@dataclass\nclass SessionConfig:\n    browser: BrowserConfig\n    lifetime: Optional[int] = None\n    keep_alive: Optional[bool] = None\n```\n\n## Error Handling\n\nThe SDK provides a custom `BFloatError` class for error handling:\n\n```python\ntry:\n    session = await bfloat.create_session(config)\nexcept BFloatError as error:\n    print(f'Status: {error.status}')\n    print(f'Message: {error.message}')\n    print(f'Response: {error.response}')\n```\n\n## Complete Example\n\n```python\nfrom bfloat import BfloatSDK, BFloatError, DEFAULT_BROWSER_CONFIG, SessionConfig\nimport asyncio\n\nasync def run_browser_session():\n    bfloat = BfloatSDK('your-api-key')\n\n    try:\n        # List existing sessions\n        sessions = await bfloat.list_sessions()\n        print(f'Active sessions: {len(sessions)}')\n\n        # Create a new session\n        config = SessionConfig(\n            browser=DEFAULT_BROWSER_CONFIG,\n            lifetime=3600\n        )\n        session = await bfloat.create_session(config)\n\n        print(f'New session: {session.id}')\n        print(f'Debug URL: {session.debug_info.ws_debugger_url}')\n\n        # Get session details\n        details = await bfloat.get_session(session.id)\n        print(f'Session status: {details.status}')\n\n        # Stop session\n        await bfloat.stop_session(session.id)\n        print('Session stopped successfully')\n\n    except BFloatError as error:\n        print(f'BFloat API error: {error}')\n        print(f'Status: {error.status}')\n    except Exception as error:\n        print(f'Unexpected error: {error}')\n    finally:\n        await bfloat.close()\n\n# Run the example\nif __name__ == \"__main__\":\n    asyncio.run(run_browser_session())\n```\n\n## Development\n\n```bash\n# Install dependencies\npoetry install\n\n# Run tests\npytest\n\n# Build\npoetry build\n\n# Generate documentation\npdoc --html bfloat_sdk\n```\n\n## Contributing\n\nWe welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Support\n\n- Documentation: [https://docs.bfloat.ai](https://docs.bfloat.ai)\n- Issues: [GitHub Issues](https://github.com/bfloat-inc/python-sdk-python/issues)\n- Email: support@bfloat.ai\n\n## Security\n\nIf you discover a security vulnerability, please send an email to security@bfloat.ai. All security vulnerabilities will be promptly addressed.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python SDK for interacting with the bfloat.ai API",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/bfloat-ai/python-sdk"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2bb77b8d9cb011df086d5d1d21b24c9826884f9787ec61d7d9afe6be68b8ffa9",
                "md5": "094396955952f9d6605892b1d22d0883",
                "sha256": "6bf31cb9dfc48197f3dc05e9ecaabcddaa73c9272c15ee60c31955821c744ff8"
            },
            "downloads": -1,
            "filename": "bfloat-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "094396955952f9d6605892b1d22d0883",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6306,
            "upload_time": "2024-11-05T03:04:05",
            "upload_time_iso_8601": "2024-11-05T03:04:05.195628Z",
            "url": "https://files.pythonhosted.org/packages/2b/b7/7b8d9cb011df086d5d1d21b24c9826884f9787ec61d7d9afe6be68b8ffa9/bfloat-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cd7a550c0874aefb53867f2fb662ed75ede8284d52b81bcd27ada2e5ade1688b",
                "md5": "569956ee7c3b22c3c0d1d320e54157e8",
                "sha256": "2a7a0a933540a324b310f91f51758c9bfe4e6a64002458228e7d5a1b97f55b11"
            },
            "downloads": -1,
            "filename": "bfloat-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "569956ee7c3b22c3c0d1d320e54157e8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6993,
            "upload_time": "2024-11-05T03:04:06",
            "upload_time_iso_8601": "2024-11-05T03:04:06.122528Z",
            "url": "https://files.pythonhosted.org/packages/cd/7a/550c0874aefb53867f2fb662ed75ede8284d52b81bcd27ada2e5ade1688b/bfloat-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-05 03:04:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bfloat-ai",
    "github_project": "python-sdk",
    "github_fetch_exception": true,
    "lcname": "bfloat"
}
        
Elapsed time: 0.34377s