> For AI agents: the complete documentation index is available at https://anyformat.swc.rs/llms.txt, the full documentation bundle is available at https://anyformat.swc.rs/llms-full.txt.

# Getting started

## Requirements

- Node.js 18 or later, for the Node.js packages.
- Python 3.10 or later, for the Python packages.

## Install a package

Install the package of each format family that you use. The examples on this
page use the image family.

**Node.js**


```sh [npm]
npm add @swc/anyformat-image
```

```sh [yarn]
yarn add @swc/anyformat-image
```

```sh [pnpm]
pnpm add @swc/anyformat-image
```

```sh [bun]
bun add @swc/anyformat-image
```

```sh [deno]
deno add npm:@swc/anyformat-image
```

**Python**

```sh
pip install anyformat-image
```

## Detect the format of a file

Give the bytes of a file to `detect`. The function needs only the first bytes of
the file. 64 bytes are enough for every image format.

**Node.js**

```js
import { readFile } from 'node:fs/promises'
import { detect } from '@swc/anyformat-image'

detect(await readFile('photo.avif'))
// => { format: 'avif', mimeType: 'image/avif' }
```

**Python**

```python
from pathlib import Path

import anyformat_image

anyformat_image.detect(Path("photo.avif").read_bytes())
# => DetectedFormat(format='avif', mime_type='image/avif')
```

When the format is not recognized, `detect` returns `null` in Node.js and `None`
in Python.

## List the supported formats

`supportedFormats` returns the identifier of each format that `detect` can
return.

**Node.js**

```js
import { supportedFormats } from '@swc/anyformat-image'

supportedFormats()
// => ['png', 'jpeg', 'gif', 'webp', 'avif', 'heic', 'jxl', 'tiff', 'bmp', 'ico', 'qoi']
```

**Python**

```python
import anyformat_image

anyformat_image.supported_formats()
# => ['png', 'jpeg', 'gif', 'webp', 'avif', 'heic', 'jxl', 'tiff', 'bmp', 'ico', 'qoi']
```

## Next steps

- Read the [API reference](https://anyformat.swc.rs/api.md) of each format family.
- Read [Development](https://anyformat.swc.rs/guide/development.md) to build anyformat from source.
