Skip to main content

A simple Python wrapper for the Telegraph API

Project description

YTelegraph

PyPi Package Version Supported Python versions PyPi downloads PyPi status License

YTelegraph is a simple, user-friendly Python wrapper for the Telegraph API. Publish your content to Telegraph with just a few lines of code!

Table of Contents

Installation

pip install your-telegraph

Quick Start

Publish a Telegraph page in just 4 lines of code:

from ytelegraph import TelegraphAPI

ph = TelegraphAPI()
content = "# Hello, Telegraph!\n\nThis is my first Telegraph page using YTelegraph."
ph_link = ph.create_page_md("My First Page", content)
print(f"Your page is live at: {ph_link}")

That's it! No need to worry about tokens, account creation, or complex API calls.

Key Features

  • Simple: Create and publish Telegraph pages with minimal code.
  • Markdown Support: Write your content in Markdown and let YTelegraph handle the conversion.
  • Flexible Token Management: Use your own token or let YTelegraph handle account creation.
  • Full API Access: For advanced users, complete access to Telegraph API features is available.

Why YTelegraph?

"All you need is a title and content. That's it. Just like https://telegra.ph/, but in Python."

YTelegraph brings the simplicity of Telegraph's web interface to your Python projects. Whether you're creating a bot, a content management system, or just want to quickly publish some content, YTelegraph makes it easy.

More Examples

Create a page from a Markdown file

from ytelegraph import TelegraphAPI

ph = TelegraphAPI()

with open('my_article.md', 'r') as f:
    content = f.read()

ph_link = ph.create_page_md("My Article", content)
print(f"Article published at: {ph_link}")

Use your own Telegraph token

from os import environ
from ytelegraph import TelegraphAPI

TELEGRA_PH_TOKEN = environ.get("TELEGRA_PH_TOKEN")

ph = TelegraphAPI(TELEGRA_PH_TOKEN)

This method is useful if you want to use an existing Telegraph account or manage tokens yourself.

Advanced Usage

Try and see the example/second_usage.py at here.

Token Management

YTelegraph offers flexible token management:

  1. Automatic: If no token is provided, YTelegraph creates a new account and manages the token for you.
  2. Environment Variable: Set the TELEGRA_PH_TOKEN environment variable, and YTelegraph will use it automatically.
  3. Direct Input: Pass your token directly to the TelegraphAPI constructor.

Choose the method that best fits your workflow and security requirements.

Create Account

While YTelegraph handles account creation automatically, you might want to create your own Telegraph account for more control. Here's a quick guide:

  1. Visit this URL in your browser (feel free to customize the parameters): https://api.telegra.ph/createAccount?short_name=Sandbox&author_name=Anonymous

    • Replace Sandbox with any name to help you remember this account (only visible to you)
    • Change Anonymous to your preferred author name (default for your articles)
    • Or keep them as is – it's totally fine!
  2. After accessing the link, you'll see a response like this:

    {
      "ok": true,
      "result": {
        "short_name": "Sandbox",
        "author_name": "Anonymous",
        "author_url": "",
        "access_token": "abcedfeghijklmnopqrstuvwxyz",
        "auth_url": "https://edit.telegra.ph/auth/qwertyuiop"
      }
    }
    
  3. The access_token (in this example, abcedfeghijklmnopqrstuvwxyz) is what you'll use in your code. (Note: This is not a real token!)

For more details, check out the Telegraph API documentation.

YTelegraph makes this process super easy, but it's good to know how to do it manually if you ever need to.

Testing

To run the basic integration tests, execute the examples in the examples/ directory:

python examples/basic_usage.py
python examples/second_usage.py

Versioning

For the versions available, see the CHANGELOG.md file.

Support

If you encounter any problems or have any questions, please open an issue on our GitHub repository.

Contributing

We welcome contributions! Feel free to submit issues or pull requests.

License

YTelegraph is released under the MIT License. See LICENSE for details.

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

your_telegraph-0.2.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

your_telegraph-0.2.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file your_telegraph-0.2.1.tar.gz.

File metadata

  • Download URL: your_telegraph-0.2.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for your_telegraph-0.2.1.tar.gz
Algorithm Hash digest
SHA256 24282dabb1d0ca7d6de137acb3e4313e2ad5fe9fffa135c593d9ce9c8eda4242
MD5 9adfd7e04234cc2a4d77edd6d8fdb7f7
BLAKE2b-256 fa0868d65e469bc63554763d56c312dbb6c2dd207dfed05cb42446b543bf844f

See more details on using hashes here.

Provenance

The following attestation bundles were made for your_telegraph-0.2.1.tar.gz:

Publisher: python-publish.yml on alterxyz/YTelegraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file your_telegraph-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: your_telegraph-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for your_telegraph-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 184219b8ee7646c6c29027f906f4ecd2ac0bcf4d2faa865446f8a0dbba736fc0
MD5 3b15d013cc3edcf4fd48ae305b7ade33
BLAKE2b-256 3231c25ee3a23016677a7c7328f83e237b59574b6e23457c624ebcfca9552118

See more details on using hashes here.

Provenance

The following attestation bundles were made for your_telegraph-0.2.1-py3-none-any.whl:

Publisher: python-publish.yml on alterxyz/YTelegraph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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