Skip to main content

fsql

The fsql package's goal is to simplify the task of getting data from any file system, local or remote, possibly divided into multiple partitions, into a single data frame. The package has querying capabilities, thus the name stands for "file system query language".

Quick Start

The core is installed just via pip install fsql. Additional filesystem support or output representation is installed via pip install fsql[s3] or pip install fsql[dask].

For examples of usage (and sort-of documentation), we use selected test files accompanied with explanatory comments:

  1. basic usage,
  2. date range utils,
  3. integrating with Dask.

Use Cases & Features

The canonical usecase is that you have data on S3 stored e.g. as <table_name>/year=<yyyy>/month=<mm>/day=<dd>/<filename>.csv, and you want to fetch a part of it (e.g., a week from the last month, every Monday last year, ...) as a single Pandas or Dask DataFrame, via a short command -- without having to write the boto3 crawl, the bytes2csv, the csv2pandas, etc. The crawl/query part is traditionally covered by metastores, such as Hive Metastore or Glue Data Catalog.

Why, then, would you use fsql?

  • If you don't have the metastore set up, using fsql is faster and has no operation/maintenance costs.
  • If your processing engine (Pandas, Dask, ...) does not cooperate with the metastore out of the box, plugging it to fsql is simpler.
  • If the storage structure is not supported by the metastore -- e.g., usually the <columnName>=<value> is required, yet we often encounter just <value> with the column name provided externally.
  • If the name of the file bears any information, e.g., it is the timestamp of the event the file represent, or some id of the data source -- metastores usually treat individual filenames as meaningless (for a good reason, as distributed engines such as Spark just use hashes), however, we treat them as regular column.
  • If the condition for fetching data is not trivial (not available as SQL function -- e.g., you want to fetch only those files for which some column returns 1 when fed to an ML model), the implementation provided by fsql is more efficient than manually fetching all partitions from metastore and evaluating locally.
  • You query from multiple filesystems at once (S3 and GDrive), and you don't have a unifying layer -- fsql changes between those just by changing the URL prefix. This can be particularly handy in some integration tests, if don't want to query real S3 but keep the same code (and point it at local filesystem or Minio instead... we find it less hassle and more value than with mocking, which fits more to unit tests).

However, if you have your metastore and are happy with it, there is no reason not to use it. There are some advantages which fsql will likely never cover:

  • A metastore may allow for data discovery based on additional metadata -- but fsql is not backed by any persistence to hold such data.
  • There is no difference between a partition column and regular column inside the data, you conveniently query both the same way and may combine them -- however, we believe that due to severe performance difference, those should be kept separated until the data is fetched to the user's computing process.

There is also some overlap with pandas.io.sql -- that one, however, focuses solely on pandas whereas fsql can adapt to any data processing tool which allows partition-based input specification (e.g., Spark). On the other hand, pandas.io.sql has good integration with sql-alchemy and traditional database queries, whereas fsql is focused on partitioned file systems only.

Supported & Underlying Technologies

This package is based on fsspec -- anything supported by that can be plugged in. At the moment, we have test coverage only for local filesystem and s3. Adding a new one requires mostly ensuring that authentication and URL parsing will work correctly, and taking care of some weird cornercases such as caching in s3fs.

The supported output representations are at the moment Pandas, Dask and list[dict]. Adding a new one requires implementing a conversion from a Iterable[(Path, FileSystem)] to the desired object.

The query language is rather simplistic, so no proper parser & grammar & query optimiser is used at the moment.

License

BSD 3

Metadata

Release files for fsql 0.23.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 fsql 0.23.0
File Size Uploaded Provenance
fsql-0.23.0.tar.gz 32.1 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 56.0 kB

Release files / fsql-0.23.0.tar.gz

Download URL fsql-0.23.0.tar.gz
Size 32.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6319574957f1e605f55e58b08594cfe01bc651a1dbee8e9a048364b84a5f1d5f
BLAKE2b-256 checksum
How to use checksums
02428309fc77f497542b49871f8f84d381fd35246cb5d4e28ea7c3ac04fab992
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / fsql-0.23.0-py3-none-any.whl

Download URL fsql-0.23.0-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4c93698dcca4afdf7a7ef43992ec29c80e985996d563c9ce9fa5a97ed704035
BLAKE2b-256 checksum
How to use checksums
867df1325b8be91373bbca2a073dc875af31a38e855257932a7741d57fa7d373
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for fsql 0.23.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.

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