A CLI tool to automate competitive programming workflow - fetch, test, and submit solutions
Project description
slave-cp
A powerful CLI tool that automates your competitive programming workflow โ fetch problems, test locally, and auto-submit solutions.
โจ Features
- ๐ Quick Setup โ One command to initialize your workspace and session cookies
- ๐ Codeforces Native โ Works flawlessly with Codeforces
- ๐ Auto-Fetch โ Automatically scrapes problems and test cases via Cloudscraper
- ๐งช Local Testing โ Run solutions against sample inputs with rich diff tables
- ๐ค Headless Auto-Submit โ Submit directly from terminal without opening a browser
- ๐จ Rich Terminal UI โ Beautiful colored output with status indicators
- ๐ง 23 Languages Supported โ From C++ to Rust, Python to Haskell
๐ฆ Installation
pip install slave-cp
Requirements:
- Python 3.7 or higher
- Compiler/interpreter for your chosen language (e.g.,
g++for C++,pythonfor Python)
๐ Quick Start
1. Initialize Your Workspace
slave-cp init ~/competitive
This will:
- Set your workspace directory
- Save Codeforces session cookie (RCJSESSIONID) for headless submission
- Set your default programming language
2. Fetch a Contest
Codeforces:
slave-cp fetch CF1234
This creates a folder with all problems and their test cases:
CF1234/
โโโ A/
โ โโโ input1.txt
โ โโโ output1.txt
โ โโโ input2.txt
โ โโโ output2.txt
โโโ B/
โ โโโ input1.txt
โ โโโ ...
โโโ ...
3. Write Your Solution
Create your solution file in the problem folder:
cd CF1234/A
touch solution.cpp # or .py, .java, etc.
4. Test Locally
slave-cp run A
Or with explicit contest ID:
slave-cp run A --contest CF1234
Output:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Test Case 1 โ
AC โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Input: 5 3 โ
โ Expected: 8 โ
โ Got: 8 โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
All test cases passed! ๐
Submit to Codeforces? [y/N]:
5. Submit (Optional)
If all tests pass, you'll be prompted to submit. Type y to submit directly to the platform.
๐ Commands
| Command | Description |
|---|---|
slave-cp init <path> |
Initialize workspace and save session cookie |
slave-cp fetch <contest-id> |
Fetch problems and test cases from a contest |
slave-cp run <problem> |
Test your solution against sample inputs |
slave-cp run <problem> --contest <id> |
Test with explicit contest ID |
slave-cp config |
Display current configuration |
slave-cp list |
List all contests in workspace |
slave-cp check |
Check installed compilers/interpreters |
slave-cp --help |
Show help message |
๐ Supported Platforms
Codeforces
- Contest format:
CF<contest-number>(e.g.,CF1234) - Scrapes problems seamlessly using
cloudscraper - Ultra-fast headless submission using session cookies
- Real-time verdict polling
๐ป Supported Languages (23)
Auto-detected by file extension:
| Language | Extension | Compiler/Interpreter Required |
|---|---|---|
| C++ | .cpp |
g++ |
| C | .c |
gcc |
| Python | .py |
python or python3 |
| Java | .java |
javac + java |
| Kotlin | .kt |
kotlinc + kotlin |
| Go | .go |
go |
| Rust | .rs |
rustc |
| C# | .cs |
dotnet-script |
| Ruby | .rb |
ruby |
| JavaScript | .js |
node |
| TypeScript | .ts |
ts-node |
| Haskell | .hs |
ghc |
| Scala | .scala |
scalac + scala |
| D | .d |
dmd |
| Pascal | .pas |
fpc |
| Perl | .pl |
perl |
| PHP | .php |
php |
| Swift | .swift |
swift |
| Lua | .lua |
lua |
| R | .r |
Rscript |
| Dart | .dart |
dart |
| F# | .fs |
dotnet fsi |
| PyPy | .pypy |
pypy or pypy3 |
Run slave-cp check to verify which languages are available on your system.
โ๏ธ Configuration
Configuration is stored at ~/.slave-cp/config.json:
{
"workspace": "/Users/username/competitive",
"language": "cpp",
"codeforces": {
"handle": "tourist",
"cookie": "your-rcjsessionid-cookie-here"
}
}
View current config:
slave-cp config
Update workspace or credentials:
slave-cp init ~/new-workspace
๐งช Testing Workflow
Verdicts
| Verdict | Symbol | Meaning |
|---|---|---|
| AC | โ | Accepted โ correct output |
| WA | โ | Wrong Answer โ output mismatch |
| TLE | โฑ๏ธ | Time Limit Exceeded (>5s) |
| RE | ๐ฅ | Runtime Error โ program crashed |
| CE | ๐ง | Compilation Error โ code didn't compile |
Diff Table
When output doesn't match:
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Test Case 2 โ WA โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Input: 10 20 30 โ
โ Expected: 60 โ
โ Got: 50 โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
๐ง Troubleshooting
Codeforces Submission Blocked / Token Missing
Problem: You get an error like "CSRF token not found" or "HTTP Error" during submission.
Solution: Your Codeforces session cookie has probably expired.
- Log in to Codeforces in your browser again.
- Open Developer Tools (F12) > Application > Cookies.
- Copy the value of the
RCJSESSIONIDcookie. - Run
slave-cp initto update it.
Compiler Not Found
Problem: g++: command not found
Solution:
# macOS
xcode-select --install
# Ubuntu/Debian
sudo apt-get install build-essential
# Windows
Install MinGW or use WSL
Check installed compilers:
slave-cp check
๐ Advanced Usage
Custom Time Limit
By default, solutions timeout after 5 seconds. This is hardcoded but can be adjusted in future versions.
Multiple Solutions
You can have multiple solution files (e.g., solution.cpp, brute.cpp) in the same problem folder. slave-cp run will use the first one it finds matching your default language.
Manual Test Cases
Add your own test cases by creating input{n}.txt and output{n}.txt pairs in the problem folder.
๐ค Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
Development setup:
git clone https://github.com/block-plant/slave-cp.git
cd slave-cp
pip install -e .[dev]
pytest
๐ License
This project is licensed under the MIT License โ see the LICENSE file for details.
๐ค Author
Ayush Kunwar Singh (@block-plant)
๐ Acknowledgments
- Built with Click for CLI
- Styled with Rich for beautiful terminal output
- Headless scraping powered by Cloudscraper
๐ Project Status
- โ
Live on PyPI:
pip install slave-cp - โ Codeforces support
- โ 23 languages supported
- โ Zero-dependency headless submission in v0.2.0!
๐ Links
- PyPI: https://pypi.org/project/slave-cp/
- GitHub: https://github.com/block-plant/slave-cp
- Issues: https://github.com/block-plant/slave-cp/issues
- Documentation: USER_MANUAL.md
Happy Coding! ๐
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 slave_cp-0.2.0.tar.gz.
File metadata
- Download URL: slave_cp-0.2.0.tar.gz
- Upload date:
- Size: 26.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f58f1912d76bae60fdafb5a4e2b2a8762faf49293525707cdeae10589122c77
|
|
| MD5 |
85de388dd402fb2c6384c8b3acc50b8c
|
|
| BLAKE2b-256 |
a055a6f94a83d7ce8608da0e719d09b4a33b2b2efa8cdb7020d34eaacd31f501
|
File details
Details for the file slave_cp-0.2.0-py3-none-any.whl.
File metadata
- Download URL: slave_cp-0.2.0-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be0edb610598f775bf84e3f061afe282dfe5455f28c0e2ece0458ddd67cf96b5
|
|
| MD5 |
2f678ee0fde7627ccabf189c54d6a3cf
|
|
| BLAKE2b-256 |
72b7d430250b28147e23c18710ba6f91d2162cee3872c91ff541444c8047bcc9
|