Skip to main content

A python wrapper for the pythonanywhere.com API

Project description

MyPythonAnywhere

A python async package to communicate with PythonAnywhere api.

Installation

The beta package is available at PyPi.

Get Started

Requirements

  1. Api Token: get your api token from pythonanywhere account page.

  2. Determine if your account is US_Based or EU_Based ( It's commonly US. )

  3. Your username.

Create Client

from mypythonanywhere import AccountType, FriendlyPythonAnywhereClient

client = FriendlyPythonAnywhereClient(
    username='MerrilleChoate',
    token='API_TOKEN',
    account_type=AccountType.UsBased
)

Send Requests

Get cpu usage.

>>> result = await client.cpu.get_cpu_usage()
>>> print(result)
# CpuUsage(daily_cpu_limit_seconds=100, next_reset_time='2022-04-17T11:23:40', daily_cpu_total_usage_seconds=0.0) 

Get all of your consoles.

>>> result = await client.consoles.get_consoles()
>>> print(result)
# [Console(id=24036640, user='MerrilleChoate', executable='python2.7', arguments='', working_directory=None, name='Python2.7 console 24036640', console_url='/user/MerrilleChoate/consoles/24036640/', console_frame_url='/user/MerrilleChoate/consoles/24036640/frame/')]

A full example

Send requests one by one

import asyncio

async def main():

    client = FriendlyPythonAnywhereClient(
        username='MerrilleChoate',
        token='API_TOKEN',
        account_type=AccountType.UsBased
    )

    consoles = await client.console.get_consoles()
    print(consoles)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Send a batch of requests using one session

import asyncio

async def main():

    client = FriendlyPythonAnywhereClient(
        username='MerrilleChoate',
        token='API_TOKEN',
        account_type=AccountType.UsBased
    )

    async with client:
        consoles = await client.console.get_consoles()
        for x in consoles:
            await client.console.kill_console(x.id)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Direct Call

from mypythonanywhere.pythonanywhere import PythonAnywhereClient
from mypythonanywhere.types.requests.console_requests import GetConsoleInfo

client = PythonAnywhereClient(
    # --- sniff ---
)

console = await client(GetConsoleInfo(123456789)) # Console

🍟 Not all methods are implemented yet! ...

Contribute

There're api methods that are not implemented. following the order of https://help.pythonanywhere.com/pages/API, methods related to files and below are yet to implement.

Implement Methods?

Take a look at requests dir for examples of implementing api methods.

All you need is to inherit from BaseRequest[T] ( where T is the method return type ). then filling the abstract methods, unless you face something new.

Automated tests

Tests are missing for most of methods.

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

mypythonanywhere-0.1.5rc0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

mypythonanywhere-0.1.5rc0-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file mypythonanywhere-0.1.5rc0.tar.gz.

File metadata

  • Download URL: mypythonanywhere-0.1.5rc0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for mypythonanywhere-0.1.5rc0.tar.gz
Algorithm Hash digest
SHA256 4f9705dec06cfa3f02fd76a760c01c61c4bef2724b9649148a5bf458c9ca3506
MD5 5c59297e15b5583420bec779392a7f87
BLAKE2b-256 16a5df5dceb7a3c879274df9ec15c3a646fdb0165fb72944565f72cac3ec2fd1

See more details on using hashes here.

File details

Details for the file mypythonanywhere-0.1.5rc0-py3-none-any.whl.

File metadata

File hashes

Hashes for mypythonanywhere-0.1.5rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb1e5deb474dbbfb14338c4d5acae42910b19596898e6f6f0ed42245afddb17f
MD5 14b5e983dce58cfc36815b259b59478d
BLAKE2b-256 4381c1912d920aba765383021d0e4ea242798ae926e0d5958aaa8ff3b96c6110

See more details on using hashes here.

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