Skip to main content

Cloudflare AI Python Wrapper

This Python library provides a convenient way to interact with the Cloudflare AI API asynchronously, allowing you to leverage the power of Cloudflare's AI models in your applications. With this wrapper, you can easily integrate AI-driven features into your projects without the hassle of handling API requests and responses manually.

Installation

Install from PyPI:

pip install cloudflareai

Install from Github:

python -m pip install -U git+https://github.com/alexraskin/cloudflareai-py

Or build from source:

git clone
cd cloudflareai
python setup.py install

Usage

Import the CloudflareAI class and the desired model enums. Then, create an instance of the CloudflareAI class with your Cloudflare API key and account identifier. You can then use the instance to call the desired AI model.

import asyncio

from cloudflareai import (
    CloudflareAI,
    AiTextToImageModels,
    AiTextGenerationModels,
    AiImageClassificationModels,
)


async def main():
    ai = CloudflareAI(
        Cloudflare_API_Key=<Your Token>,
        Cloudflare_Account_Identifier=<Account ID>,
    )

    text = await ai.TextGeneration(
        prompt="You are helpful",
        system_prompt="Hello, my name is Alex",
        model_name=AiTextGenerationModels.CODE_LLAMA_7B,
    )
    image = await ai.TextToImage(
      prompt="a Cat",
      model_name=AiTextToImageModels.XL_BASE
    )
    print(text.text) # returns string
    print(image.image) # returns bytes

    ### Also get status codes
    print(text.status_code)
    print(image.status_code)

asyncio.run(main())

Models

This wrapper also includes enums for AI models, making it easier to select the desired model for your tasks. Available enums include:

  • AiImageClassificationModels
  • AiTranslationModels
  • AiTextGenerationModels
  • AiSpeechRecognitionModels
  • AiTextToImageModels
  • TranslationLanguages

Contributing

If you'd like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Submit a pull request with a clear description of your changes.

License

Mozilla Public License Version 2.0 (MPL-2.0) - See LICENSE for more information.

Metadata

Release files for cloudflareai 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cloudflareai 0.9.0
File Size Uploaded Provenance
cloudflareai-0.9.0.tar.gz 13.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cloudflareai 0.9.0
File Interpreter ABI Platform
cloudflareai-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.6 kB

Release files / cloudflareai-0.9.0.tar.gz

Download URL cloudflareai-0.9.0.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
30ca44ad645bc91cc79a511b3ab2fa810539504b8fcf0c1260412648844d9528
BLAKE2b-256 checksum
How to use checksums
f3f6924b6b09617220583763d0e02550cd3ccc82257a6fc331f1a6532015c77c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / cloudflareai-0.9.0-py3-none-any.whl

Download URL cloudflareai-0.9.0-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79b37ea514f8478f32b0f71e991f82f38413acb1667af67b9c77169751eff444
BLAKE2b-256 checksum
How to use checksums
2d240f8bfd7b0d2762c5de3bd48c04a006d1d097e8e276f04a17f0d6c1fdf682
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Security for cloudflareai 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page