A comprehensive Python library for working with Logseq knowledge graphs
Project description
๐ Logseq Python Library
The most comprehensive Python library for Logseq knowledge graph interaction
Transform your Logseq workflow with programmatic access to every major feature. From basic note-taking to advanced task management, academic research, and knowledge graph analytics - this library supports it all.
โจ Comprehensive Feature Support
๐ฏ Task Management & Workflows
- โ Complete Task System: TODO, DOING, DONE, LATER, NOW, WAITING, CANCELLED, DELEGATED, IN-PROGRESS
- โ Priority Levels: A, B, C with full parsing and filtering
- โ Scheduling: SCHEDULED dates with time and repeaters (+1w, +3d)
- โ Deadlines: DEADLINE tracking with overdue detection
- โ Workflow Analytics: Completion rates, productivity metrics
๐ Advanced Content Types
- โ Code Blocks: Language detection, syntax highlighting support
- โ Mathematics: LaTeX/Math parsing ($$math$$, \(inline\))
- โ Queries: {{query}} and #+begin_query support
- โ Headings: H1-H6 hierarchical structure
- โ References: ((block-id)) linking and {{embed}} support
- โ Properties: Advanced property parsing and querying
๐๏ธ Organization & Structure
- โ Namespaces: project/backend hierarchical organization
- โ Templates: Template variables {{variable}} parsing
- โ Aliases: Page alias system with [[link]] support
- โ Whiteboards: .whiteboard file detection
- โ Hierarchies: Parent/child page relationships
๐ Knowledge Graph Analytics
- โ Graph Insights: Connection analysis, relationship mapping
- โ Content Statistics: Block type distribution, tag usage
- โ Productivity Metrics: Task completion trends
- โ Workflow Summaries: Advanced task analytics
๐ Powerful Query System
- โ 25+ Query Methods: Task states, priorities, content types
- โ Date Filtering: Scheduled, deadline, creation date queries
- โ Content Filtering: Code language, math content, headings
- โ Relationship Queries: Block references, embeds, backlinks
- โ Advanced Combinations: Chain multiple filters fluently
Installation
pip install logseq-py
Or for development:
git clone https://github.com/yourusername/logseq-python.git
cd logseq-python
pip install -e .
๐ Quick Start
Basic Setup
from logseq_py import LogseqClient, TaskState, Priority
# Initialize client with your Logseq graph directory
client = LogseqClient("/path/to/your/logseq/graph")
graph = client.load_graph()
๐ Task Management
# Find all high-priority tasks
urgent_tasks = client.query().blocks().has_priority(Priority.A).execute()
# Get overdue tasks
from datetime import date
overdue = client.query().blocks().has_deadline().custom_filter(
lambda block: block.deadline.date < date.today()
).execute()
# Find completed tasks
completed = client.query().blocks().has_task_state(TaskState.DONE).execute()
# Get workflow summary
workflow = client.graph.get_workflow_summary()
print(f"Completion rate: {workflow['completed_tasks']}/{workflow['total_tasks']}")
๐ป Code & Content Analysis
# Find all Python code blocks
python_code = client.query().blocks().is_code_block(language="python").execute()
# Get math/LaTeX content
math_blocks = client.query().blocks().has_math_content().execute()
# Find all headings
headings = client.query().blocks().is_heading().execute()
# Get blocks with references
linked_blocks = client.query().blocks().has_block_references().execute()
๐ Advanced Analytics
# Get comprehensive graph insights
insights = client.graph.get_graph_insights()
# Analyze namespaces
for namespace in client.graph.get_all_namespaces():
pages = client.graph.get_pages_by_namespace(namespace)
print(f"{namespace}/: {len(pages)} pages")
# Find most connected pages
for page_name, connections in insights['most_connected_pages'][:5]:
print(f"{page_name}: {connections} backlinks")
โ๏ธ Content Creation
# Add journal entry with task
client.add_journal_entry("TODO Review project documentation #urgent")
# Create a structured page
content = """# Project Planning
- TODO Set up initial framework [#A]
SCHEDULED: <2024-01-15 Mon>
- Code review checklist
- [ ] Security audit
- [ ] Performance testing"""
client.create_page("Project Alpha", content)
๐ฏ Real-World Use Cases
๐ Project Management
- Track tasks across multiple projects with priorities and deadlines
- Generate productivity reports and completion metrics
- Automate workflow status updates and notifications
- Analyze team performance and bottlenecks
๐ฌ Academic Research
- Parse and analyze LaTeX mathematical content
- Extract and organize research notes with citations
- Track paper progress and review status
- Generate bibliographies and reference networks
๐ป Software Development
- Document code examples with syntax highlighting
- Track bugs and feature requests with priority levels
- Organize documentation by namespace (frontend/backend)
- Generate code statistics and language usage reports
๐ Knowledge Management
- Build comprehensive knowledge graphs with relationships
- Track learning progress with spaced repetition
- Organize information hierarchically with namespaces
- Generate insights about information consumption patterns
๐จ Creative Work
- Organize creative projects with visual whiteboards
- Track inspiration and reference materials
- Manage creative workflows with custom task states
- Analyze creative output patterns and productivity
๐ ๏ธ Advanced Examples
Task Automation
# Find all overdue high-priority tasks and generate a report
from datetime import date, timedelta
overdue_urgent = (client.query()
.blocks()
.is_task()
.has_priority(Priority.A)
.has_deadline()
.custom_filter(lambda b: b.deadline.date < date.today())
.execute())
for task in overdue_urgent:
days_overdue = (date.today() - task.deadline.date).days
print(f"โ ๏ธ OVERDUE {days_overdue} days: {task.content}")
Content Analysis
# Analyze your coding activity across languages
code_stats = {}
for block in client.query().blocks().is_code_block().execute():
lang = block.code_language or 'unknown'
code_stats[lang] = code_stats.get(lang, 0) + 1
print("๐ Code block distribution:")
for lang, count in sorted(code_stats.items(), key=lambda x: x[1], reverse=True):
print(f" {lang}: {count} blocks")
Knowledge Graph Analysis
# Find your most referenced pages (knowledge hubs)
page_refs = {}
for block in client.query().blocks().has_block_references().execute():
for ref in block.referenced_blocks:
page_refs[ref] = page_refs.get(ref, 0) + 1
print("๐ Most referenced content:")
for ref, count in sorted(page_refs.items(), key=lambda x: x[1], reverse=True)[:10]:
print(f" {ref}: {count} references")
๐ Documentation
- ๐ Complete API Reference - Comprehensive API documentation
- ๐ฏ Basic Usage Examples - Get started quickly
- ๐ Advanced Queries - Complex search examples
- ๐จ Advanced Features - All new features showcase
- ๐ค Data Export/Import - Backup and analysis
- ๐งช Test Suite - Comprehensive testing examples
Requirements
- Python 3.8+
- Logseq graph (local directory)
License
This project is licensed under the MIT License - see the LICENSE file for details.
The MIT License is a permissive license that allows for commercial use, modification, distribution, and private use, with the only requirement being that the license and copyright notice must be included with any substantial portions of the software.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file logseq_python-0.3.0.tar.gz.
File metadata
- Download URL: logseq_python-0.3.0.tar.gz
- Upload date:
- Size: 177.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
545491639bf698071b55335b9026c5a0a40f00733913952fab915d675b3f543f
|
|
| MD5 |
116046be56ea903082e99eea8a625a62
|
|
| BLAKE2b-256 |
d61ff86c800bb8359efbe55bdfd567d43696ca15eae91f5392f2f835fe1981d8
|
File details
Details for the file logseq_python-0.3.0-py3-none-any.whl.
File metadata
- Download URL: logseq_python-0.3.0-py3-none-any.whl
- Upload date:
- Size: 142.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2360b3e74c635e6ee4549e5898ec7c56e8f491dfbcbc4021eb0c35700451760
|
|
| MD5 |
f1d5809acdb159fd964adb5bc3095465
|
|
| BLAKE2b-256 |
e501ad3dfdba58b1b0237cbc4600c5b39bb7d0d7ec620de0db8ec5958a5d6a34
|