Skip to main content

Carbon

Create beautiful carbon code images using python or terminal.

This is an unofficial asynchronous python wrapper for carbon.now.sh which can be also be used inside cli.

Installation

pip install carbon-api

Directly from Source

git clone https://github.com/StarkBotsIndustries/Carbon

cd Carbon

python setup.py install

Example

Example Carbon Image

Usage

Using as an Asynchronous Library

import asyncio
from carbon import Carbon

client = Carbon()


async def main():
    img = await client.create("Your code here")
    print(img)


asyncio.run(main())

Options

You can pass globally usable options' values to Carbon class

from carbon import Carbon

client = Carbon(
    downloads_dir=os.getcwd(),  # Defaults to current directory
    colour="rgba(171, 184, 195, 1)",  # Hex or rgba color
    shadow=True,  # Turn on/off shadow
    shadow_blur_radius="68px",
    shadow_offset_y="20px",
    export_size="2x",  # resolution of exported image, e.g. 1x, 3x
    font_size="14px",
    font_family= "Hack",  # font family, e.g. JetBrains Mono, Fira Code.
    first_line_number=1,
    language="auto",  # programing language for properly highlighting
    line_numbers=False,  # turn on/off, line number
    horizontal_padding="56px",
    vertical_padding="56px",
    theme="seti",  # code theme
    watermark=False,  # turn on/off watermark
    width_adjustment=True,  # turn on/off width adjustment
    window_controls= True,  # turn on/off window controls
    window_theme=None
)

Same options are also available in Carbon.create method, which override the global options.

You can also specify the file name to the create method. Path to the image will be returned by the function.

path = await client.create(file="my-code.png")  # Path will be downloads_dir/file 
print(path)

Using CLI

$ carbon-app

Create beautiful carbon code images using python or terminal

Options:
  -v, --version         check the current version installed
  -f FILE, --file FILE  pass file path to read code from
  -c CODE, --code CODE  pass some code to make carbon

Enjoy the program :)

You can pass the file path using the file argument.

carbon-app --file path_to_file

or simply

carbon-app -f path_to_file

For example:

carbon-app --file main.py

Here main.py should be in the same directory.


You can also directly pass code (not recommended)

carbon-app --code your_code_here

or simply

carbon-app -c your_code_here

CLI is in beta version and other options aren't available currently. If you're interested in that functionality, let me know.

Credits

Community and Support

Telegram Channel - StarkBots

Telegram Chat - StarkBotsChat

Metadata

Release files for carbon-api 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for carbon-api 0.1
File Size Uploaded Provenance
carbon-api-0.1.tar.gz 11.4 kB Without provenance Details

Release files / carbon-api-0.1.tar.gz

Download URL carbon-api-0.1.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
882457ebe3e0df81ae146b349de417fe17169879678601129cb19461426ae507
BLAKE2b-256 checksum
How to use checksums
270ae1bcc380bae7d1bcfb9e32beaa103356c88a8e9e055eb8308a251bca0989
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Security for carbon-api 0.1

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page