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:
    ...  # 401 or 403: the key is wrong or lacks access
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.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 picsha 0.3.0
File Size Uploaded Provenance Actions
picsha-0.3.0.tar.gz 7.6 kB Without provenance Details for picsha-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 17.0 kB

Release files / picsha-0.3.0.tar.gz

Download URL picsha-0.3.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
26cd5ab24dc1027693e09c1b17b670612c1b4fc9160833353986512b6492b242
BLAKE2b-256 checksum
How to use checksums
a3e5f20db120ece02159f035a2c7b42dd3b8ce47841db6847b07cf652d4e6855
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.0-py3-none-any.whl

Download URL picsha-0.3.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
532f04251a424fd89e56eb3d1748d8a4c4211a95adb84066aa294c5b7ed60b41
BLAKE2b-256 checksum
How to use checksums
0f9a67c80832f9ff19766926f78054f1f974cfd6006716e0dd31861a02880b9a
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.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.

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