Skip to main content

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

  1. Create an account on Showcode App to fetch the API key.

  2. Sign in to the account and create an API token:

    1. Token name: Provide a name to the token which you can remember where it is being used
    2. Check "read" permissions
    3. 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

    Create API token snapshot

  3. Export an environment variable to store the token in the terminal: export SHOWCODE_API_KEY={API Token}

  4. Now, you're ready to use the package in your applications.

Installation

  1. Create a virtual environment: conda create -n code-snapshot-test-env -y python=3.8
  2. Activate the environment: conda activate code-snapshot-test-env
  3. Install the package pip install code-snapshot

Usage

  1. Set the Showcode API token as an environment variable following Getting started section

  2. 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")
    
  3. Run the python script python main.py. This should generate a file code_snapshot.png in the same directory as main.py.

  4. It should look like this: code_snapshot

  5. You can use cs.generate_snapshot(settings, editor) to consume bytes if required.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code-snapshot-0.2.4.tar.gz (162.5 kB view hashes)

Uploaded Source

Built Distribution

code_snapshot-0.2.4-py3-none-any.whl (16.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page