# Python SDK Quickstart

> Install the Copyleaks Python SDK, authenticate, and submit your first scan in under 5 minutes with this step-by-step guide.

This guide will walk you through installing the official Python SDK and running your first scan. In just a few minutes, you'll be able to run your first scan directly from your Python application.

Before you start, ensure you have the following:
- An active Copyleaks account. If you don't have one, **[sign up for free](https://api.copyleaks.com/signup)**.
- You can find your API key on the **[API Dashboard](https://api.copyleaks.com/dashboard)**.
## Get Started

<Steps>
  <Step title="Installation">
    First, install the official `copyleaks` package from PyPI into your project using pip:

    ```bash
    pip install copyleaks
    ```
  </Step>

  <Step title="Quick Example: Scan Text">
    <Warning>
    Remember to replace the placeholder `YOUR_EMAIL_ADDRESS` and `YOUR_API_KEY` with your actual credentials.
    </Warning>

    ```python title="scan_text.py"
    import base64
    from copyleaks.copyleaks import Copyleaks
    from copyleaks.exceptions.command_error import CommandError
    from copyleaks.models.submit.document import FileDocument
    from copyleaks.models.submit.properties.scan_properties import ScanProperties

    # --- Your Credentials ---
    EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS'
    KEY = 'YOUR_API_KEY'
    # --------------------

    # Log in to the Copyleaks API
    try:
        auth_token = Copyleaks.login(EMAIL_ADDRESS, KEY)
        print(" Logged in successfully!")
    except CommandError as ce:
        print(f" Login failed: {ce}")
        exit()

    # Prepare your content for scanning
    # You can scan a URL, a local file, or raw text.
    # This example scans a simple string of text.
    print("Submitting text for scanning...")
    text_to_scan = "Hello world, this is a test."
    base64_content = base64.b64encode(text_to_scan.encode()).decode()

    # Configure the scan
    # A unique scan ID for this submission
    scan_id = "my-first-scan" 
    scan_properties = ScanProperties("https://your-server.com/webhook/{STATUS}")
    scan_properties.set_sandbox(True) # Turn on sandbox mode for testing

    file_submission = FileDocument(base64_content, "test.txt")
    file_submission.set_properties(scan_properties)

    # Submit the scan to Copyleaks
    Copyleaks.submit_file(auth_token, scan_id, file_submission)
    print(f" Scan submitted successfully! Scan ID: {scan_id}")
    print("You will be notified via your webhook when the scan is complete.")
    ```
  </Step>

  <Step title="Understanding the Code">
    The example code performs four main actions to submit a scan:

    1.  **Login:** It authenticates with your email and API key to get a secure login token from the Copyleaks server. This token is required for all subsequent requests.
    2.  **Prepare Content:** It takes a simple string of text and encodes it into Base64 format. The SDK requires content to be in this format for submission.
    3.  **Configure Scan:** It creates a `ScanProperties` object to define the scan's behavior. We enable `sandbox` mode for safe testing without using credits and provide a `webhook` URL.
    4.  **Submit for Scanning:** It sends the prepared content and its configuration to the Copyleaks API. The process is asynchronous, meaning you don't have to wait for the results. Instead, Copyleaks will notify your webhook URL once the scan is complete.
  </Step>
</Steps>

## Next Steps

<CardGroup cols={2}>
  <Card title="GitHub Repository" icon="github" href="https://github.com/Copyleaks/Python-Plagiarism-Checker">Check the official Copyleaks Python SDK repository on GitHub for installation and usage details.</Card>
  <Card title="PyPi Package" icon="python" href="https://pypi.org/project/copyleaks/">Install the official Copyleaks Python package from PyPI for easy integration.</Card>
</CardGroup>

<CardGroup cols={2}>
  <Card title="Check for Plagiarism" icon="magnifying-glass" href="/guides/authenticity/detect-plagiarism-text">
    Detect plagiarism in text documents using the Copyleaks API. Search billions of sources to find unoriginal content.
  </Card>
  <Card title="Detect AI-Generated Content" icon="robot" href="/guides/ai-detector/ai-text-detection">
    Detect AI-generated text via sync or async API calls. This guide covers sync detection, see the Authenticity API Guide for async.
  </Card>
  <Card title="Assess Grammar and Writing Quality" icon="spell-check" href="/guides/writing/check-grammar">
    Get writing and grammar suggestions via API. Authenticate, submit text, and access full details in the docs.
  </Card>
  <Card title="Moderate Text" icon="shield-halved" href="/guides/moderation/moderate-text">
    Scan and moderate text content for unsafe or policy-relevant material across 10+ categories.
  </Card>
</CardGroup>
