Skip to main content

flati

Python version latest version license download NO WAR

Flatten nested iterable object (Pure-Python implementation)

Japanese document is available: https://qiita.com/yukinoi/items/9570c76034c28bdae0a8

Installation

$ pip install flati

Usage

import flati

iterable = [(1, 2, 3), (4, (5, 6))]
list(flati.flatten(iterable))
# => [1, 2, 3, 4, 5, 6]

# The flati.flatten function returns a generator
import types
isinstance(flati.flatten(iterable), types.GeneratorType)
# => True

# If you want to avoid flattening specific type, then use "ignore" parameter
iterable = [('abc'), ('def', ('g', 'hi'))]
list(flati.flatten(iterable, ignore=str))
# => ['abc', 'def', 'g', 'hi']

# The flatten_non_str function is alias of "flatten(iterable, ignore=str)"
iterable = [('abc'), ('def', ('g', 'hi'))]
list(flati.flatten_non_str(iterable))
# => ['abc', 'def', 'g', 'hi']

Tips

If you want to flatten numpy.ndarray, I recommend using following methods:

  • numpy.ravel()

  • ndarray.reshape(-1)

  • ndarray.flatten() # This method is a bit slow because it makes a copy

Contribution

Contributions are welcome.

See https://github.com/ikegami-yukino/flati/blob/master/CONTRIBUTING.md

CHANGES

0.2.1 (2025-08-15)

  • Add flatten_non_str function that alias of flatten(iterable, ignore=str)

0.2.0 (2025-08-02)

  • Add stub files according to PEP 561

  • Support Python 3.9, 3.10, 3.11, 3.12, 3.13

0.1.2 (2019-12-31)

  • Support Python 3.8

0.1.1 (2019-1-28)

  • Support Python 2.7

0.1 (2019-1-27)

  • First release

Metadata

Release files for flati 0.2.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 flati 0.2.1
File Size Uploaded
flati-0.2.1.tar.gz 4.6 kB Details

Built distribution (wheel)

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

Total release size: 11.7 kB

Release files / flati-0.2.1.tar.gz

Download URL flati-0.2.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0e23b2b3664eefdc80cc59bf45927a86765eec5ef54e61a05335afde47523911
BLAKE2b-256 checksum
How to use checksums
522c2a9aad4f627f668b094f32e0f2741b38bf7c9313012f2e7233da15fd6dbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / flati-0.2.1-py3-none-any.whl

Download URL flati-0.2.1-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
507ff989d38b3cf80cdffb424c0f0afdf8a27874170cc0d27bf58c60bcdb0258
BLAKE2b-256 checksum
How to use checksums
8a2d0a2ce180ab3c745e297bb296753fb65a4662ab69d421d108f70f8cc91cfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

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