code_snapshot - A Python library for interacting with the Showcode api.
Project description
Code snapshot
Create a snapshot image for your code to share the formatted code anywhere. We use SHOWCODE api to create a PNG image for the specified code snippet.
Getting started
-
Create an account on Showcode App to fetch the API key.
-
Sign in to the account and create an API token:
- Token name: Provide a name to the token which you can remember where it is being used
- Check "read" permissions
- Copy the token displayed and store somewhere in safe. Note: This token won't be shown again, so you need to paste it before you close the window
-
Export an environment variable to store the token in the terminal:
export SHOWCODE_API_KEY={API Token}
-
Now, you're ready to use the package in your applications.
Installation
- Create a virtual environment:
conda create -n code-snapshot-test-env -y python=3.8
- Activate the environment:
conda activate code-snapshot-test-env
- Install the package
pip install -i https://test.pypi.org/simple/ code-snapshot
Usage
-
Set the Showcode API token as an environment variable following Getting started section
-
Write a python script as following:
from code_snapshot.code_snapshot import CodeSnapshot from code_snapshot.models import CodeSnapshotSettings, CodeSnapshotEditor if __name__ == "__main__": settings=CodeSnapshotSettings( title="Hello world in Python", ) editor=CodeSnapshotEditor( value=""" def greet(name): print(f"Hello {name}!") greet("World") """ ) cs = CodeSnapshot() cs.save_snapshot(settings, editor, filepath="./code_snapshot.png")
-
Run the python script
python main.py
. This should generate a filecode_snapshot.png
in the same directory asmain.py
. -
It should look like this:
-
You can use
cs.generate_snapshot(settings, editor)
to consumebytes
if required.
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
Hashes for code_snapshot-0.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2809316722409bf43568c4645a9cbcce2a1d6f5473b8e713aeeadceeb92d4a90 |
|
MD5 | 9f71308de4178612559961c0f03303e5 |
|
BLAKE2b-256 | 25cdc58cc58dfe68e6049616005cfcf3dd6109a5d66e00356f5440a712f21b2a |