flatdata-py
Python 3 implementation of flatdata.
Running the tests
python3 -m pytest
Basic usage
Once you have created a flatdata schema file, you can generate a Python module to read your existing flatdata archive:
flatdata-generator --gen py --schema locations.flatdata --output-file locations.py
Performance tips
flatdata-py supports two data access patterns with very different performance characteristics on large archives.
Iterating over a vector yields one Python object per element. Each field access unpacks bits from the underlying memory-mapped data. This is fine for accessing individual elements or small ranges, but has significant per-element overhead for bulk operations:
count = sum(1 for x in archive.links if x.speed_limit > 100)
For bulk operations, use the vectorized access methods that read fields directly into NumPy arrays:
# single column access, returns a pandas DataFrame
df = archive.links.speed_limit
count = len(df[df['speed_limit'] > 100])
# full NumPy structured array with all fields
arr = archive.links.to_numpy()
count = int(np.sum(arr['speed_limit'] > 100))
# slices work too
arr = archive.links[1000:2000].to_numpy()
df = archive.links[::10].to_data_frame()
- Use
vector.field_name(column access) when you only need one or a few fields. - Use
vector.to_numpy()orvector.to_data_frame()when you need all fields at once. - Use
vector[i].fieldfor random access to individual elements. - The underlying data is memory-mapped; the OS pages it from disk on demand. Vectorized results are materialized as NumPy arrays in RAM.
Using the inspector
flatdata-py comes with a handy tool called the flatdata-inspector to inspect the contents of an archive:
- from the
flatdata-pysource directory:
./inspector.py
# or
python3 -m flatdata.lib.inspector
- if you want to install
flatdata-py:
pip3 install flatdata-py[inspector] # the inspector feature requires IPython
flatdata-inspector -p /path/to/my/flatdata.archive
Using the writer
flatdata-writer is an addition to flatdata-py that can create flatdata archives from a flatdata schema, with the following limitations:
-
does not allow adding additional sub-archives to an existing archive
-
supports only bulk-writing (no streaming)
-
not optimized for performance
-
from the
flatdata-pysource directory
./writer.py --schema archive.flatdata --output-dir testdir --json-file data.json --resource-name resourcename
#or
python3 -m flatdata.lib.writer --schema archive.flatdata --output-dir testdir --json-file data.json --resource-name resourcename
Note that the flatdata-writer CLI tool can only write one resource at a time. For archives that have multiple non-optional
resources, the tool has to be executed separately for each resource. Only after all resources have been written can the archive be opened.
- if you want to install flatdata-py:
pip3 install flatdata-py[writer]
flatdata-writer --schema archive.flatdata --output-dir testdir --json-file data.json --resource-name resourcename
Metadata
Release files for flatdata-py 0.4.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flatdata_py-0.4.12.tar.gz | 16.8 kB | Without provenance | Details for flatdata_py-0.4.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flatdata_py-0.4.12-py3-none-any.whl | Python 3 | none | any | Details for flatdata_py-0.4.12-py3-none-any.whl |
Total release size: 40.6 kB
Release files / flatdata_py-0.4.12.tar.gz
| Download URL | flatdata_py-0.4.12.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c4f1736270dcea1e4da3f62b5f75b1146d27a372b696a83597a90657e61810f5
|
|
BLAKE2b-256 checksum How to use checksums |
d6186836ca307821a6b696df805a43416ae1ca90bf8fd45a92cb1d510e179179
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.8
|
Release files / flatdata_py-0.4.12-py3-none-any.whl
| Download URL | flatdata_py-0.4.12-py3-none-any.whl |
|---|---|
| Size | 23.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ec4f2968212ceeeed787fe07e9772193cb6cde2ae99329abef879783769568f3
|
|
BLAKE2b-256 checksum How to use checksums |
e78333fb057bd2968440353a9ff515f09f72ac4f3e7289bd9291e698dc9dd0fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.8
|
Security for flatdata-py 0.4.12
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.