Pragyan
AI-Powered DSA Question Solver with Video Explanations
🚀 Quick Install
pip install pragyan
⚡ Quick Start
In Your Python Script
from pragyan import Pragyan
# Initialize with your API key
solver = Pragyan(api_key="your-gemini-api-key")
# Solve from LeetCode URL
result = solver.solve("https://leetcode.com/problems/two-sum/", language="python")
print(result.solution.code)
From Terminal
# Interactive mode (recommended)
pragyan interactive
# Quick solve from URL
pragyan solve "https://leetcode.com/problems/two-sum/" --video
Pragyan is a Python package that helps developers understand and solve Data Structures and Algorithms (DSA) problems. It leverages AI to analyze problems, generate optimized solutions, and create animated explanation videos.
Table of Contents
- Features
- Architecture
- Installation
- Quick Start
- CLI Reference
- Python API
- Configuration
- Supported Languages
- Video Generation
- Examples
- Troubleshooting
- Contributing
- License
Features
| Feature | Description |
|---|---|
| Multi-Platform Scraping | Extract problems from LeetCode, GeeksforGeeks, Codeforces, HackerRank |
| AI-Powered Analysis | Identify patterns, data structures, and optimal approaches |
| Multi-Language Solutions | Generate code in 11+ programming languages |
| Video Explanations | Animated visualizations using Manim |
| Step-by-Step Breakdown | Detailed algorithm walkthroughs |
| Test Case Generation | Auto-generate test cases for validation |
| Verbose Logging | Real-time progress updates during execution |
Architecture
System Overview
+------------------------------------------------------------------+
| PRAGYAN SYSTEM |
+------------------------------------------------------------------+
| |
| +-------------+ +-------------+ +------------------+ |
| | INPUT | | CORE | | OUTPUT | |
| +-------------+ +-------------+ +------------------+ |
| | - URL | | - Scraper | | - Solution Code | |
| | - Text |---->| - Analyzer |---->| - Explanation | |
| | - API Key | | - Solver | | - Video (MP4) | |
| +-------------+ | - Generator | | - Test Cases | |
| +-------------+ +------------------+ |
| |
+------------------------------------------------------------------+
Component Architecture
pragyan/
|
+-- cli.py Command Line Interface (Click + Rich)
| |
| +-- Interactive prompts
| +-- Progress logging
| +-- Result display
|
+-- main.py Orchestration Layer
| |
| +-- Pragyan class (main entry point)
| +-- Component coordination
| +-- Pipeline management
|
+-- scraper.py Web Scraping Module
| |
| +-- LeetCode adapter
| +-- GFG adapter
| +-- Generic HTML parser
| +-- Selenium for dynamic content
|
+-- llm_client.py AI Integration Layer
| |
| +-- Gemini client (Google AI)
| +-- Groq client (open models)
| +-- Response parsing
| +-- Error handling
|
+-- solver.py Solution Generation
| |
| +-- Problem analysis
| +-- Code generation
| +-- Complexity analysis
| +-- Test case creation
|
+-- video_generator.py Video Creation Module
| |
| +-- Manim scene generation
| +-- Animation templates
| +-- Rendering pipeline
|
+-- models.py Data Models (Pydantic)
| |
| +-- Question, Solution
| +-- VideoConfig, LLMConfig
| +-- ProgrammingLanguage enum
|
+-- logger.py Logging System
|
+-- Rich console output
+-- Progress tracking
+-- User engagement
Processing Pipeline
+--------+ +----------+ +----------+ +--------+ +-------+
| INPUT |--->| SCRAPE |--->| ANALYZE |--->| SOLVE |--->| VIDEO |
+--------+ +----------+ +----------+ +--------+ +-------+
| | | | |
v v v v v
URL or Question Analysis Solution MP4 File
Text Object Dict Object
| | |
v v v
- Title - Topics - Code
- Description - Concept - Explanation
- Examples - Approach - Complexity
- Constraints - Edge Cases - Steps
Data Flow Diagram
+------------------+
| User Input |
| (URL/Text/API) |
+--------+---------+
|
v
+------------------+
| QuestionScraper |
| - Fetch HTML |
| - Parse content |
| - Extract data |
+--------+---------+
|
v
+------------------+
| LLM Client |
| - Gemini API |
| - Groq API |
+--------+---------+
|
+--------------+--------------+
| |
v v
+----------------+ +----------------+
| Analyzer | | Solver |
| - Identify | | - Generate |
| patterns | | code |
| - Find concept | | - Explain |
| - Edge cases | | steps |
+-------+--------+ +-------+--------+
| |
+-------------+---------------+
|
v
+------------------+
| Video Generator |
| - Build scenes |
| - Render Manim |
| - Export MP4 |
+--------+---------+
|
v
+------------------+
| Output |
| - Code + Explain |
| - Video file |
+------------------+
Installation
Basic Installation
pip install pragyan
Video Generation Dependencies
For video generation with Manim:
Windows:
pip install manim
choco install ffmpeg
macOS:
pip install manim
brew install ffmpeg
Linux (Ubuntu/Debian):
pip install manim
sudo apt-get install ffmpeg
Verify Installation
pragyan version
Quick Start
Interactive Mode (Recommended)
pragyan interactive
This launches a guided session that:
- Prompts for problem URL or text
- Selects programming language
- Configures API provider
- Displays real-time progress
- Generates solution and video
Command Line
# Solve from URL
pragyan solve -u https://leetcode.com/problems/two-sum -p gemini -k YOUR_API_KEY
# Solve from text
pragyan solve -t "Find two numbers that add up to target" -l python -p gemini -k KEY
# Analyze only (no solution)
pragyan analyze https://leetcode.com/problems/two-sum -p gemini -k KEY
CLI Reference
| Command | Description |
|---|---|
pragyan interactive |
Interactive mode with prompts |
pragyan solve |
Solve a problem |
pragyan analyze |
Analyze without solving |
pragyan languages |
List supported languages |
pragyan version |
Show version |
Solve Options
| Option | Short | Description |
|---|---|---|
--url |
-u |
Problem URL |
--text |
-t |
Problem text |
--language |
-l |
Programming language |
--provider |
-p |
AI provider (gemini/groq) |
--api-key |
-k |
API key |
--no-video |
Skip video generation | |
--output-dir |
-o |
Video output directory |
--quality |
-q |
Video quality (low/medium/high) |
Python API
Basic Usage
from pragyan import Pragyan
# Initialize
pragyan = Pragyan(
provider="gemini",
api_key="YOUR_API_KEY"
)
# Solve from URL
result = pragyan.process(
"https://leetcode.com/problems/two-sum",
language="python",
generate_video=True
)
# Access results
print(result["solution"].code)
print(result["solution"].time_complexity)
print(f"Video: {result['video_path']}")
Advanced Usage
from pragyan import Pragyan, ProgrammingLanguage, VideoConfig
# Custom configuration
video_config = VideoConfig(
output_dir="./videos",
video_quality="high_quality",
resolution="1080p"
)
pragyan = Pragyan(
provider="gemini",
api_key="YOUR_API_KEY",
video_config=video_config
)
# Step-by-step control
question = pragyan.scrape_question("https://leetcode.com/problems/binary-search")
analysis = pragyan.analyze(question)
solution = pragyan.solve(question, ProgrammingLanguage.JAVA, analysis)
video_path = pragyan.generate_video(question, solution, analysis)
# Print details
print(f"Title: {question.title}")
print(f"Topics: {analysis['topics']}")
print(f"Concept: {analysis['main_concept']}")
print(f"Approach: {solution.approach}")
print(f"Time: {solution.time_complexity}")
print(f"Space: {solution.space_complexity}")
Class Reference
Pragyan
| Method | Description | Returns |
|---|---|---|
scrape_question(url) |
Fetch problem from URL | Question |
parse_question(text) |
Parse problem from text | Question |
analyze(question) |
Analyze problem | Dict |
solve(question, lang, analysis) |
Generate solution | Solution |
generate_video(question, solution, analysis) |
Create video | Path |
process(input, lang, video) |
Complete pipeline | Dict |
generate_test_cases(question, n) |
Generate test cases | List |
Configuration
Environment Variables
export PRAGYAN_API_KEY="your_api_key"
API Keys
Google Gemini (Recommended):
- Visit Google AI Studio
- Create API key
- Use with
provider="gemini"
Groq:
- Visit Groq Console
- Create API key
- Use with
provider="groq"
VideoConfig Options
| Parameter | Type | Default | Description |
|---|---|---|---|
output_dir |
Path | ~/Downloads | Video output directory |
video_quality |
str | medium_quality | low/medium/high_quality |
fps |
int | 30 | Frames per second |
pixel_width |
int | 1920 | Video width |
pixel_height |
int | 1080 | Video height |
background_color |
str | #1e1e1e | Background hex color |
Supported Languages
| Language | Aliases |
|---|---|
| Python | python, py |
| Java | java |
| C++ | cpp, c++ |
| C | c |
| JavaScript | javascript, js |
| TypeScript | typescript, ts |
| Go | go, golang |
| Rust | rust, rs |
| Kotlin | kotlin, kt |
| Swift | swift |
| C# | csharp, c#, cs |
Video Generation
Video Structure
- Introduction - Problem title and topics
- Problem Overview - Description and key points
- Concept Explanation - Core algorithm/technique
- Step-by-Step Approach - Algorithm walkthrough
- Code Display - Syntax-highlighted solution
- Example Walkthrough - Trace through example
- Complexity Analysis - Time and space complexity
- Summary - Key takeaways
Quality Settings
| Quality | Resolution | Render Time |
|---|---|---|
| low | 480p | Fast |
| medium | 720p | Moderate |
| high | 1080p | Slow |
Examples
Two Sum Problem
from pragyan import Pragyan
pragyan = Pragyan(provider="gemini", api_key="KEY")
result = pragyan.process("https://leetcode.com/problems/two-sum")
print(result["solution"].code)
# def twoSum(nums, target):
# seen = {}
# for i, num in enumerate(nums):
# complement = target - num
# if complement in seen:
# return [seen[complement], i]
# seen[num] = i
# return []
Custom Problem Text
from pragyan import Pragyan
pragyan = Pragyan(provider="groq", api_key="KEY")
problem = """
Given an array of integers, find the maximum subarray sum.
Example:
Input: [-2, 1, -3, 4, -1, 2, 1, -5, 4]
Output: 6 (subarray [4, -1, 2, 1])
Constraints:
- 1 <= length <= 10^5
- -10^4 <= array[i] <= 10^4
"""
question = pragyan.parse_question(problem)
solution = pragyan.solve(question, "cpp")
print(solution.code)
Multiple Languages
from pragyan import Pragyan, ProgrammingLanguage
pragyan = Pragyan(provider="gemini", api_key="KEY")
question = pragyan.scrape_question("https://leetcode.com/problems/binary-search")
analysis = pragyan.analyze(question)
for lang in [ProgrammingLanguage.PYTHON, ProgrammingLanguage.JAVA, ProgrammingLanguage.CPP]:
solution = pragyan.solve(question, lang, analysis)
print(f"\n--- {lang.value} ---")
print(solution.code)
Troubleshooting
Common Issues
API Key Error:
Error: Invalid API key
Solution: Verify your API key is correct and active.
Video Generation Fails:
Error: Manim not found
Solution: Install Manim and FFmpeg:
pip install manim
# Windows: choco install ffmpeg
# macOS: brew install ffmpeg
# Linux: sudo apt install ffmpeg
Scraping Fails:
Error: Could not fetch URL
Solution: Some sites require Selenium. Install Chrome/ChromeDriver:
pip install selenium webdriver-manager
Project Structure
pragyan/
├── src/
│ └── pragyan/
│ ├── __init__.py
│ ├── main.py
│ ├── cli.py
│ ├── models.py
│ ├── llm_client.py
│ ├── scraper.py
│ ├── solver.py
│ ├── video_generator.py
│ ├── animations.py
│ ├── logger.py
│ └── utils.py
├── tests/
├── examples/
├── pyproject.toml
├── README.md
└── LICENSE
Contributing
Contributions are welcome. Please submit a Pull Request.
- Fork the repository
- Create a feature branch
- Make changes
- Submit PR
License
MIT License - see LICENSE file.
Links
- Repository: github.com/Kamalllx/pragyan_pypi
- PyPI: pypi.org/project/pragyan
- Issues: github.com/Kamalllx/pragyan_pypi/issues
Built by Kamal
Metadata
Release files for pragyan 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pragyan-1.1.2.tar.gz | 72.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pragyan-1.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 137.9 kB
Release files / pragyan-1.1.2.tar.gz
| Download URL | pragyan-1.1.2.tar.gz |
|---|---|
| Size | 72.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f9a6c22f3bbcf867f9f678b1e2bbb8c10eea21752142bae53d25299bd4f360ee
|
|
BLAKE2b-256 checksum How to use checksums |
7ae384d9d63fdaa5137a67949c040d94295a544c7c53efb9e20616629da8f4ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / pragyan-1.1.2-py3-none-any.whl
| Download URL | pragyan-1.1.2-py3-none-any.whl |
|---|---|
| Size | 65.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
825c86fd95b43bd5ac0a95e8f4328eebcd8bc9e5ba548b5cb2f0c4d048f20422
|
|
BLAKE2b-256 checksum How to use checksums |
90534c5f6cd323eae3df32fe8afbf20d0adf784bb7bc743584e3afc5d8e1d7a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for pragyan 1.1.2
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.