Package: malloy
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 thePython Package Index(PyPI).python3-mpipinstallmalloyResourcesMalloy Language GitHub- Primary location for the malloy language source, documentation, and informationMalloy Language- A quick introduction to the languageeCommerce Example Analysis- A walkthrough of the basics on an ecommerce dataset (BigQuery public dataset)Modeling Walkthrough- An introduction to modeling via the Iowa liquor sales public data set (BigQuery public dataset)Malloy on YouTube- Watch demos / walkthroughs of MalloyJoin The CommunityJoin ourMalloy Slack Community!Use this community to ask questions, meet other Malloy users, and share ideas with one another.UseGitHub issuesto provide feedback, suggest improvements, report bugs, and start new discussions.Syntax ExamplesRun named query from malloy file:importasyncioimportmalloyfrommalloy.data.duckdbimportDuckDbConnectionasyncdefmain():home_dir="/path/to/samples/duckdb/imdb"withmalloy.Runtime()asruntime:runtime.add_connection(DuckDbConnection(home_dir=home_dir))data=awaitruntime.load_file(home_dir+"/5_movie_complex.malloy").run(named_query="horror_combo")dataframe=data.df()print(dataframe)if__name__=="__main__":asyncio.run(main())Get SQL from inline query using malloy file as source:importasyncioimportmalloyfrommalloy.data.duckdbimportDuckDbConnectionasyncdefmain():home_dir="/path/to/samples/duckdb/faa"withmalloy.Runtime()asruntime:runtime.add_connection(DuckDbConnection(home_dir=home_dir))[sql,connection]=awaitruntime.load_file(home_dir+"/flights.malloy").get_sql(query="""query: flights -> {where: carrier ? 'WN' | 'DL', dep_time ? @2002-03-03group_by:flight_date is dep_time.daycarrieraggregate:daily_flight_count is flight_countaircraft.aircraft_countnest: per_plane_data is {top: 20group_by: tail_numaggregate: plane_flight_count is flight_countnest: flight_legs is {order_by: 2group_by:tail_numdep_minute is dep_time.minuteorigin_codedest_code is destination_codedep_delayarr_delay}}}""")print(sql)if__name__=="__main__":asyncio.run(main())Write inline malloy model source and run query:importasyncioimportmalloyfrommalloy.data.duckdbimportDuckDbConnectionasyncdefmain():home_dir="/path/to/samples/duckdb/auto_recalls"withmalloy.Runtime()asruntime:runtime.add_connection(DuckDbConnection(home_dir=home_dir))data=awaitruntime.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(query="""query: auto_recalls -> {group_by: Manufactureraggregate:recall_countpercent_of_recalls}""")dataframe=data.df()print(dataframe)if__name__=="__main__":asyncio.run(main())DevelopmentInitial setupgitsubmoduleinit
gitsubmoduleupdate
python3-mpipinstall-rrequirements.dev.txt
scripts/gen-services.shRegenerate Protobuf filesscripts/gen-protos.shTestspython3-mpytest