An open API service indexing awesome lists of open source software.

https://github.com/thinmanj/logseq-python-library

๐Ÿ Comprehensive Python library for Logseq knowledge graph interaction. Read, query, and modify Logseq data programmatically with advanced search capabilities.
https://github.com/thinmanj/logseq-python-library

automation data-export knowledge-graph logseq markdown note-taking python query-builder

Last synced: 3 days ago
JSON representation

๐Ÿ Comprehensive Python library for Logseq knowledge graph interaction. Read, query, and modify Logseq data programmatically with advanced search capabilities.

Awesome Lists containing this project

README

          

# ๐Ÿ 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.

[![Python 3.8+](https://img.shields.io/badge/Python-3.8+-blue.svg)](https://python.org)
[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/thinmanj/logseq-python-library/blob/main/LICENSE)
[![GitHub Stars](https://img.shields.io/github/stars/thinmanj/logseq-python-library.svg)](https://github.com/thinmanj/logseq-python-library/stargazers)

## โœจ **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

```bash
pip install logseq-py
```

Or for development:

```bash
git clone https://github.com/yourusername/logseq-python.git
cd logseq-python
pip install -e .
```

## ๐Ÿš€ **Quick Start**

### Basic Setup
```python
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**
```python
# 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**
```python
# 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**
```python
# 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**
```python
# 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
```python
# 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
```python
# 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
```python
# 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")
```

## ๐Ÿš€ **Warp Terminal Integration**

**NEW!** Seamlessly integrate logseq-python into your Warp terminal workflows:

- โœ… **7 Pre-built Workflows**: Task summaries, graph insights, content extraction, code stats
- โœ… **One-Command Access**: `Cmd+P` โ†’ type "Logseq" to run any workflow
- โœ… **Customizable**: Easy YAML configuration for your own workflows
- โœ… **Powerful Automation**: Daily routines, batch processing, scheduled tasks

### Quick Setup
```bash
# Copy workflow file to your Logseq graph
cd /path/to/your/logseq/graph
mkdir -p .warp/workflows
cp /path/to/logseq-python/.warp/workflows/logseq-automation.yaml .warp/workflows/

# Use in Warp: Cmd+P โ†’ "Logseq: Daily Task Summary"
```

๐Ÿ“š **[Full Warp Integration Guide](WARP_INTEGRATION.md)**

---

## ๐Ÿ“– **Documentation**

- ๐Ÿ“˜ [Complete API Reference](docs/api.md) - Comprehensive API documentation
- ๐Ÿš€ [Warp Integration Guide](WARP_INTEGRATION.md) - **NEW!** Terminal workflow automation
- ๐ŸŽฏ [Basic Usage Examples](examples/basic_usage.py) - Get started quickly
- ๐Ÿ” [Advanced Queries](examples/advanced_queries.py) - Complex search examples
- ๐ŸŽจ [Advanced Features](examples/advanced_logseq_features.py) - All new features showcase
- ๐Ÿ“ค [Data Export/Import](examples/data_export_import.py) - Backup and analysis
- ๐Ÿงช [Test Suite](tests/) - Comprehensive testing examples

## Requirements

- Python 3.8+
- Logseq graph (local directory)

## License

This project is licensed under the MIT License - see the [LICENSE](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.