{"id":45974158,"url":"https://github.com/harehare/mq-python","last_synced_at":"2026-04-06T15:03:17.642Z","repository":{"id":340992998,"uuid":"1167605094","full_name":"harehare/mq-python","owner":"harehare","description":"Python bindings for mq, a jq-like command-line tool for processing Markdown.","archived":false,"fork":false,"pushed_at":"2026-04-04T22:42:26.000Z","size":130,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-05T00:38:06.673Z","etag":null,"topics":["jq","markdown","mq","python"],"latest_commit_sha":null,"homepage":"https://mqlang.org","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harehare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-26T13:34:45.000Z","updated_at":"2026-04-04T22:42:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/harehare/mq-python","commit_stats":null,"previous_names":["harehare/mq-python"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/harehare/mq-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmq-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmq-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmq-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmq-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harehare","download_url":"https://codeload.github.com/harehare/mq-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmq-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31477013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T14:34:32.243Z","status":"ssl_error","status_checked_at":"2026-04-06T14:34:31.723Z","response_time":112,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jq","markdown","mq","python"],"created_at":"2026-02-28T16:01:47.252Z","updated_at":"2026-04-06T15:03:17.637Z","avatar_url":"https://github.com/harehare.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003emq-python\u003c/h1\u003e\n\n[![PyPI](https://img.shields.io/pypi/v/markdown-query.svg)](https://pypi.org/project/markdown-query/)\n\nPython bindings for the mq Markdown processor.\n\n## Installation\n\n```bash\npip install markdown-query\n```\n\n## Usage\n\n### Basic Usage\n\nUse the `run` function to process Markdown with mq queries:\n\n```python\nimport mq\n\n# Extract all level 1 headings\nresult = mq.run(\".h1\", \"# Hello World\\n\\n## Heading2\\n\\nText\")\nprint(result.values)  # ['# Hello World']\n\n# Extract all level 2 headings\nresult = mq.run(\".h2\", \"# Main Title\\n\\n## Section A\\n\\n## Section B\")\nprint(result.values)  # ['## Section A', '## Section B']\n\n# Get all results as a single string\nprint(result.text)  # '## Section A\\n## Section B'\n```\n\n### Filtering and Transforming\n\nUse mq query syntax to filter and transform Markdown:\n\n```python\nimport mq\n\nmarkdown = \"\"\"\n# Product\n\n## Features\nGreat features here.\n\n## Installation\nInstall instructions.\n\"\"\"\n\n# Filter headings containing specific text\nresult = mq.run('.h2 | select(contains(\"Feature\"))', markdown)\nprint(result.values)  # ['## Features']\n\n# Extract list items\nresult = mq.run(\".[]\", \"# List\\n\\n- Item 1\\n- Item 2\\n- Item 3\")\nprint(result.values)  # ['- Item 1', '- Item 2', '- Item 3']\n\n# Extract code blocks\nresult = mq.run(\".code\", \"# Code\\n\\n```python\\nprint('Hello')\\n```\")\nprint(result.values)  # [\"```python\\nprint('Hello')\\n```\"]\n```\n\n### Input Formats\n\nmq supports multiple input formats:\n\n```python\nimport mq\n\n# Markdown (default)\noptions = mq.Options()\noptions.input_format = mq.InputFormat.MARKDOWN\nresult = mq.run(\".h1\", \"# Heading\", options)\n\n# MDX (Markdown with JSX)\noptions = mq.Options()\noptions.input_format = mq.InputFormat.MDX\nresult = mq.run(\"select(is_mdx())\", \"# MDX\\n\\n\u003cComponent /\u003e\", options)\nprint(result.values)  # ['\u003cComponent /\u003e']\n\n# HTML\noptions = mq.Options()\noptions.input_format = mq.InputFormat.HTML\nresult = mq.run('select(contains(\"Hello\"))', \"\u003ch1\u003eHello\u003c/h1\u003e\u003cp\u003eWorld\u003c/p\u003e\", options)\nprint(result.values)  # ['# Hello']\n\n# Plain text\noptions = mq.Options()\noptions.input_format = mq.InputFormat.TEXT\nresult = mq.run('select(contains(\"2\"))', \"Line 1\\nLine 2\\nLine 3\", options)\nprint(result.values)  # ['Line 2']\n```\n\nAvailable input formats:\n- `InputFormat.MARKDOWN` - Standard Markdown (default)\n- `InputFormat.MDX` - Markdown with JSX\n- `InputFormat.HTML` - HTML content\n- `InputFormat.TEXT` - Plain text\n- `InputFormat.RAW` - Raw string input\n- `InputFormat.NULL` - Null input\n\n### Rendering Options\n\nCustomize the output rendering:\n\n```python\nimport mq\n\noptions = mq.Options()\noptions.input_format = mq.InputFormat.MARKDOWN\noptions.list_style = mq.ListStyle.PLUS        # Use '+' for list items\noptions.link_title_style = mq.TitleSurroundStyle.SINGLE  # Use single quotes for link titles\noptions.link_url_style = mq.UrlSurroundStyle.ANGLE       # Use angle brackets for URLs\n\nresult = mq.run(\".\", markdown, options)\n```\n\nAvailable options:\n- `ListStyle`: `DASH` (default), `PLUS`, `STAR`\n- `TitleSurroundStyle`: `DOUBLE` (default), `SINGLE`, `PAREN`\n- `UrlSurroundStyle`: `NONE` (default), `ANGLE`\n\n### HTML to Markdown Conversion\n\nConvert HTML to Markdown:\n\n```python\nimport mq\n\nhtml = \"\u003ch1\u003eHello World\u003c/h1\u003e\u003cp\u003eThis is a \u003cstrong\u003etest\u003c/strong\u003e.\u003c/p\u003e\"\nmarkdown = mq.html_to_markdown(html)\nprint(markdown)  # '# Hello World\\n\\nThis is a **test**.'\n\n# With conversion options\noptions = mq.ConversionOptions()\noptions.extract_scripts_as_code_blocks = True  # Convert \u003cscript\u003e tags to code blocks\noptions.generate_front_matter = True           # Generate front matter from metadata\noptions.use_title_as_h1 = True                 # Use \u003ctitle\u003e as h1 heading\n\nmarkdown = mq.html_to_markdown(html, options)\n```\n\n### Working with Results\n\nThe `run` function returns an `MQResult` object:\n\n```python\nimport mq\n\nresult = mq.run(\".h\", \"# H1\\n\\n## H2\\n\\n### H3\")\n\n# Get the number of results\nprint(len(result))  # 3\n\n# Access individual results by index\nprint(result[0].text)  # '# H1'\n\n# Iterate over results\nfor value in result.values:\n    print(value)\n\n# Get all results as a single string\nprint(result.text)  # '# H1\\n## H2\\n### H3'\n\n# Check if a value is in the result\nprint(\"# H1\" in result.values)  # True\n```\n\nEach `MQValue` has the following properties:\n- `text` - The string representation of the value\n- `values` - For arrays, returns the list of values\n- `markdown_type` - The type of Markdown element (e.g., `Heading`, `Code`, `List`)\n- `is_array()` - Check if the value is an array\n- `is_markdown()` - Check if the value is a Markdown element\n\n### Error Handling\n\nInvalid queries raise a `RuntimeError`:\n\n```python\nimport mq\n\ntry:\n    result = mq.run(\".invalid!!!\", \"# Heading\")\nexcept RuntimeError as e:\n    print(f\"Query error: {e}\")\n```\n\n## Development\n\n### Building from Source\n\n```bash\ngit clone https://github.com/harehare/mq\ncd mq/crates/mq-python\npip install maturin\nmaturin develop\n```\n\n### Running Tests\n\n```bash\npytest tests/\n```\n## Support\n\n- 🐛 [Report bugs](https://github.com/harehare/mq/issues)\n- 💡 [Request features](https://github.com/harehare/mq/issues)\n- 📖 [Read the documentation](https://mqlang.org/book/)\n- 📦 [PyPI package](https://pypi.org/project/markdown-query/)\n\n## License\n\nLicensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharehare%2Fmq-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharehare%2Fmq-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharehare%2Fmq-python/lists"}