Skip to main content

Malloy Logo

What is it?

Malloy is an experimental language for describing data relationships and transformations. It is both a semantic modeling language and a querying language that runs queries against a relational database. Malloy currently connects to BigQuery, and natively supports DuckDB. We've built a Visual Studio Code extension to facilitate building Malloy data models, querying and transforming data, and creating simple visualizations and dashboards.

Note: These APIs are still in development and are subject to change.

How do I get it?

Binary installers for the latest released version are available at the Python Package Index (PyPI). (Currently only available through the test respository)

python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ malloy==2022.1006a0

Resources

Join The Community

  • Join our Malloy Slack Community! Use this community to ask questions, meet other Malloy users, and share ideas with one another.
  • Use GitHub issues to provide feedback, suggest improvements, report bugs, and start new discussions.

Syntax Examples

Run named query from malloy file:

import asyncio

import malloy
from malloy.data.duckdb import DuckDbConnection


async def main():
    home_dir = "/path/to/samples/duckdb/names"
    with malloy.Runtime() as runtime:
        runtime.add_connection(DuckDbConnection(home_dir=home_dir))

        data = await runtime.load_file(home_dir + "/1_names.malloy").run("duckdb", named_query="j_names")

        dataframe = data.df()
        print(dataframe)


if __name__ == "__main__":
    asyncio.run(main())

Get SQL from inline query using malloy file as source:

import asyncio

import malloy
from malloy.data.duckdb import DuckDbConnection


async def main():
    home_dir = "/path/to/samples/duckdb/faa"
    with malloy.Runtime() as runtime:
        runtime.add_connection(DuckDbConnection(home_dir=home_dir))

        sql = await runtime.load_file(home_dir +"/2_flights.malloy").get_sql(
                query="""
                  query: flights -> {
                    where: carrier ? 'WN' | 'DL', dep_time ? @2002-03-03 
                    group_by: 
                      flight_date is dep_time.day
                      carrier
                    aggregate: 
                      daily_flight_count is flight_count
                      aircraft.aircraft_count
                    nest: per_plane_data is {
                      top: 20
                      group_by: tail_num
                      aggregate: plane_flight_count is flight_count
                      nest: flight_legs is {
                        order_by: 2
                        group_by:
                          tail_num
                          dep_minute is dep_time.minute
                          origin_code
                          dest_code is destination_code
                          dep_delay
                          arr_delay
                      }
                    }
                }
            """)

        print(sql)


if __name__ == "__main__":
    asyncio.run(main())

Write inline malloy model source and run query:

import asyncio

import malloy
from malloy.data.duckdb import DuckDbConnection


async def main():
    home_dir = "/path/to/samples/duckdb/auto_recalls"
    with malloy.Runtime() as runtime:
        runtime.add_connection(DuckDbConnection(home_dir=home_dir))

        data = await runtime.load_source("""
        source: auto_recalls is table('duckdb:auto_recalls.csv') {
          declare:
            recall_count is count()
            percent_of_recalls is recall_count/all(recall_count)*100
        }
        """).run("duckdb", query="""
        query: auto_recalls -> {
          group_by: Manufacturer
          aggregate:
            recall_count
            percent_of_recalls
        }
        """)

        dataframe = data.df()
        print(dataframe)


if __name__ == "__main__":
    asyncio.run(main())

Metadata

Release files for malloy 2023.1009

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for malloy 2023.1009
File Size Uploaded Provenance Actions
malloy-2023.1009.tar.gz 80.9 MB Without provenance Details for malloy-2023.1009.tar.gz

Built distribution (wheel)

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

Total release size: 162.3 MB

Release files / malloy-2023.1009.tar.gz

Download URL malloy-2023.1009.tar.gz
Size 80.9 MB
Tags Source
SHA-256 checksum
How to use checksums
bd00aaa571714a84f8d3939e92e5d1aafb1540a1f4d9b41c2ae1d4816c016ede
BLAKE2b-256 checksum
How to use checksums
4c118d6e6d7039a8d2cdf80d0195f738fd5a35ba85f37368514852e901284a10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.6

Release files / malloy-2023.1009-py3-none-any.whl

Download URL malloy-2023.1009-py3-none-any.whl
Size 81.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
bcb2c29eac94122635d941216b55de8ab738bd7579bdf6a7aa3476456b26ebac
BLAKE2b-256 checksum
How to use checksums
9ac4d994ab29cf814f42e1639d6cac4bdab982df1456e7feef228412f67ad69e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.6

Security for malloy 2023.1009

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.

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