Skip to main content

Picsha AI Python SDK 🐍

The official Python client for Picsha AI. Designed specifically for data scientists, computational biologists, and ML engineers.

Installation

We recommend using poetry:

poetry add picsha

Or pip:

pip install picsha

Requires Python 3.9 or later.

Quickstart

import picsha

# Or set the PICSHA_API_KEY environment variable and call picsha.Client()
client = picsha.Client(api_key="sk_your_key_here")

# 1. Semantic Search
results = client.search(
    query="fluorescent cancer cell cultures",
    mode="ai"  # Matches on meaning as well as words
)

# 2. Get transformed URLs for ML pipelines
for asset in results.assets:
    url = asset.generate_url(width=512, height=512, fit="cover", format="webp")
    print(url)

Uploading

result = client.upload(
    "./data/sample_01.heic",
    tags=["assay:123", "fluorescent"],
    metadata={"experiment": "alpha"},
)
print(result.id)

# Analysis runs in the background. Check on it:
asset = client.get_asset(result.id)
print(asset.status)

Files up to 95 MB are sent through the API. Larger files, up to 5 GiB, go straight to storage with a signed URL; the call is the same.

Searching

results = client.search(
    "fluorescent cells",
    mode="ai",            # or "standard": words in names, tags and metadata
    limit=20,
    page=1,
    filters={"type": "image", "metadata": {"experiment": "alpha"}},
)

print(results.total_count, results.has_more)
for asset in results.assets:
    print(asset.id, asset.original_filename, asset.match_score)

threshold, min_similarity and sort are optional; the API's defaults apply when you leave them out.

Listing

page = client.list_assets(type="image", tag="assay:123", limit=50)
for asset in page.assets:
    print(asset.id, asset.original_filename)

Delivery URLs

asset.generate_url(...) builds a URL that resizes and converts the asset on the fly. No request is made until you fetch it.

asset.generate_url(width=512, format="jpeg", quality=80)
# https://api.picsha.ai/v1/assets/<id>/render?w=512&fmt=jpeg&q=80

width, height, format, quality, aspect_ratio, position, radius, background, kernel, watermark and watermark_position are mapped to the API's parameter names. Any other keyword is sent as given, so the API's own names (w, h, fmt, fit, ...) work too.

Resizing, cropping, format conversion and watermarks are public URLs. Generative edits need a signed URL.

Asynchronous Support

For high-throughput workloads, an AsyncClient with the same methods is included out-of-the-box:

import picsha
import asyncio

async def main():
    async with picsha.AsyncClient(api_key="sk_your_key_here") as client:
        result = await client.search(query="cancer cells", mode="ai")
        print(f"Found {result.total_count} assets.")

asyncio.run(main())

Errors

try:
    client.get_asset("does-not-exist")
except picsha.PicshaAuthError as err:
    # 401: the key is wrong. 403: the key lacks access.
    print(err.status_code, err.details)
except picsha.PicshaAPIError as err:
    print(err.status_code, err.details)

Development

poetry install
poetry run pytest

See the notebooks/ directory for a full example.

Metadata

Release files for picsha 0.3.1

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

Source distribution (sdist)

Source distribution for picsha 0.3.1
File Size Uploaded Provenance Actions
picsha-0.3.1.tar.gz 7.7 kB Without provenance Details for picsha-0.3.1.tar.gz

Built distribution (wheel)

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

Total release size: 17.3 kB

Release files / picsha-0.3.1.tar.gz

Download URL picsha-0.3.1.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3c82d306abfcd59445d3d30562b8a5b5e3a55058a1fbae8bbcc107843fa3600a
BLAKE2b-256 checksum
How to use checksums
dec616e7bc0e0599ca24718ed02543ebca3d8311a0ad0b68a13ef66b8f3cb231
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.7 Darwin/27.2.0

Release files / picsha-0.3.1-py3-none-any.whl

Download URL picsha-0.3.1-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f114a27ce5cd204a63d0a29a5c2bf193c975a2e190c6a433b9a9bd5b2ad5dfb1
BLAKE2b-256 checksum
How to use checksums
4b514d41aed583c6206e913aa03be82fc38df9c895adb3681b1a8af599ee8f84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.7 Darwin/27.2.0

Security for picsha 0.3.1

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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