NeoCities API client library for Python 3

Download

Version 1.1.0: neocities.py

Due to limitations in the file extensions supported by NeoCities I had to upload neocities.py as a .txt file, please remove the .txt extension after downloading it.

Quick start

Download neocities.py and run pydoc3 -w neocities in the same directory to generate the documentation in html format. Python 2 and pydoc 2 may work but they are not officially supported.

No installation is required, just copy neocities.py in the same directory as your script and add from neocities import NeoCities to your code.

Examples

Importing the module and instantiating the NeoCities class:

from neocities import NeoCities

nc = NeoCities('username', 'password')

Uploading a file called example.txt stored in /home/you/neocities:

nc.upload(('example.txt', '/home/you/neocities/example.txt'))

Using an API key instead of user and password:

nc = NeoCities(key='your-key')

Documentation as generated by pydoc

Help on module neocities:

NAME
    neocities

CLASSES
    builtins.object
        NeoCities
    
    class NeoCities(builtins.object)
     |  NeoCities API client library.
     |  
     |  Methods defined here:
     |  
     |  __init__(self, user=None, password=None, key=None, url='https://neocities.org')
     |      Initialize self.
     |      
     |      user is the same as your site name, you can leave user and password
     |      empty if you are only going to use the info method. As an alternative to
     |      using an user and password combination you can specify a key that you
     |      have previously generated using the /api/key endpoint.
     |      
     |      Keyword arguments:
     |      user -- user account (default None)
     |      password -- user password (default None)
     |      key -- API key generated using the /api/key endpoint (default None)
     |      url -- base URL to use for API calls (default "https://neocities.org")
     |  
     |  delete(self, *filenames)
     |      Delete files from your site.
     |      
     |      Arguments:
     |      filenames -- a list of file names to delete
     |  
     |  info(self, sitename=None)
     |      Retrieve information about a web site.
     |      
     |      This API call can be used without logging in but in that case you are
     |      required to specify a site name.
     |      If no site name is specified it will retrieve the information of the
     |      site belonging to the username specified in the __init__ method.
     |      
     |      Keyword arguments:
     |      sitename -- the site name to retrieve information from (default None)
     |  
     |  key(self)
     |      Retrieve an API key you can use instead your username and password.
     |  
     |  list(self, path=None)
     |      Return a list of files of your site.
     |      
     |      If path is not specified it will return a list of all files.
     |      
     |      Keyword arguments:
     |      path -- the path to list files from (default None)
     |  
     |  upload(self, *files)
     |      Upload files to your site.
     |      
     |      The files parameters must be a tuple with two items, the first one is
     |      the file name you want the file to have on NeoCities and the second one
     |      is the path of the file on your disk.
     |      
     |      Arguments:
     |      files -- a list of tuples in the required format
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes defined here:
     |  
     |  RequestError = 
     |      Exception for signalling responses different than 200

VERSION
    1.1.0