---
Product: imaging
Platform: python
Page Type: kb
Canonical URL: https://kb.aspose.org/imaging/python/how-to-work-with-imaging-core-api-python
Last Updated: 2026-12-03
---

# How to Work with the Aspose.Imaging FOSS Core API in Python

Learn how to install Aspose.Imaging FOSS for Python and use detect_format, probe, probe_async, ImageInfo, and ImageFormat to detect an image's format and read its header metadata.

Aspose.Imaging FOSS for Python's public surface is five names: the functions
`detect_format()`, `probe()`, and `probe_async()`, the result type `ImageInfo`, and
the `ImageFormat` enum. This guide walks through installing the package and using
them together to detect a format and read header metadata from a file, a buffer,
and a stream.

## Step-by-Step Guide

### Step 1: Install the Package

```bash
git clone https://github.com/aspose-imaging-foss/Aspose.Imaging-FOSS-for-Python.git
cd Aspose.Imaging-FOSS-for-Python
pip install -e .
```

The package targets Python 3.10 or later and has zero dependencies beyond the
Python standard library.

---

### Step 2: Import the Functions and Types

A single import statement exposes everything you need:

```python
from aspose_imaging_foss import ImageFormat, ImageInfo, detect_format, probe
```

---

### Step 3: Probe a File by Path

`probe()` reads just enough of the file header to populate an `ImageInfo` result —
it never decodes pixel data:

```python
info = probe("photo.jpg")
print(f"{info.format}: {info.width}x{info.height}, {info.bit_depth}-bit")
```

---

### Step 4: Probe a Buffer or Stream

When the image is already in memory or came from a stream (an upload, a network
response), pass it directly instead of writing to a temporary file first:

```python
with open("photo.jpg", "rb") as f:
    data = f.read()
info_from_bytes = probe(data)

with open("photo.jpg", "rb") as stream:
    info_from_stream = probe(stream)
```

`probe()` works with both seekable and non-seekable streams.

---

### Step 5: Use detect_format() When You Only Need the Format

If you only need to branch on the format and don't need dimensions, bit depth, or
frame count, `detect_format()` skips the rest of the header parse:

```python
format = detect_format(data)
if format == ImageFormat.DICOM:
    pass  # route to DICOM-specific handling
```

---

### Step 6: Read the Nullable ImageInfo Fields Safely

`width`, `height`, `bit_depth`, and `frame_count` are nullable — they're populated
only when the detected format's header actually carries that value. `format` is
the one field always set once the header is recognized:

```python
info = probe("scan.dcm")
if info.width is not None and info.height is not None:
    print(f"{info.format}: {info.width}x{info.height}")
else:
    print(f"{info.format}: dimensions not available in this header")
```

---

### Step 7: Probe Inside an asyncio Application

`probe_async()` mirrors `probe()` for asyncio applications, avoiding blocking the
event loop:

```python
import asyncio
from aspose_imaging_foss import probe_async

async def main():
    info = await probe_async("drawing.emf")
    print(info.width, info.height)

asyncio.run(main())
```

## Common Issues and Fixes

**Format shows as `ImageFormat.UNKNOWN`.** The file's header doesn't match any of
the 14 recognized formats, or its signature appears beyond the first 132 bytes
`detect_format()` reads. Confirm the file is genuinely one of the supported
formats — `probe()`/`detect_format()` never raise for an unrecognized header, they
report `UNKNOWN` instead.

**`width`/`height` are `None` even though `format` is set.** Not every format's
header carries every field, and a truncated file may cut off before a field's
bytes. Check `format` first, then treat the rest as optional.

**Calling `probe()` when `detect_format()` would do.** `probe()` parses the full
header; `detect_format()` only reads enough to identify the format. Use
`detect_format()` if you never read `width`/`height`/`bit_depth`/`frame_count`.

**Expecting decoded pixel data.** `probe()` never decodes, renders, or converts
image content — it only reads header metadata. Decoding and pixel-level operations
require the commercial Aspose.Imaging for Python SDK.

## Frequently Asked Questions

### What happens if I probe a truncated or corrupted file?

`probe()` and `probe_async()` never raise on malformed or truncated input. They
return a partial `ImageInfo` — `format` is set whenever the header's format marker
was recognized, even if the rest of the file is cut short.

### Is probe() thread-safe?

Yes. `probe()` holds no mutable state between calls, so concurrent calls from
multiple threads are safe.

### Is there an asynchronous version of probe()?

Yes. `probe_async()` mirrors `probe()` for asyncio applications, accepting a path,
buffer, or a stream that exposes an asynchronous `read(size)` method such as
`asyncio.StreamReader`.

### Do I need to close anything?

No. `probe()`/`probe_async()` hold no resources of their own. If you pass a stream
you opened yourself, you remain responsible for closing it.

## See Also

- [Core API](https://docs.aspose.org/imaging/python/developer-guide/core-api/)
- [Features and Functionalities](https://docs.aspose.org/imaging/python/developer-guide/features/)
- [Installation](https://docs.aspose.org/imaging/python/getting-started/installation/)
- [Aspose.Imaging for Python — Enterprise Documentation](https://docs.aspose.com/imaging/python/)
- [Aspose.Imaging for Python — Enterprise Knowledge Base](https://kb.aspose.com/imaging/python/)