Python library for spartan
Go to file
Hedy Li ecf6dd7f11
fix typo in readme
2021-07-26 15:40:37 +08:00
spartan modify __repr__ for Request and update readme 2021-07-26 15:13:59 +08:00
tests initial 2021-07-15 10:14:24 +08:00
.gitignore ignore 2021-07-15 10:35:14 +08:00
LICENSE did I seriously forgot to add license lol 2021-07-15 10:41:18 +08:00
README.md fix typo in readme 2021-07-26 15:40:37 +08:00
pyproject.toml fix typo in readme 2021-07-26 15:40:37 +08:00

README.md

spartan-py

Basic spartan protocol implementation as a python library.

import spartan

res = spartan.get("spartan://mozz.us/echo", "hi")
while True:
    buf = res.read()
    if not buf:
        break
    sys.stdout.buffer.write(buf)
res.close()

Try it in the REPL:

>>> import spartan
>>> req = spartan.Request("spartan.mozz.us")
>>> req
Request(host='spartan.mozz.us', port=300, path='/') data-length=0
>>> print(req)
'spartan.mozz.us / 0'
>>> res = req.send()
>>> res
2 text/gemini
>>> res.read()
[...]
>>> res.close()

install

pip3 install spartan-py

API

  • Request(host: str, port: int = 300, path: str = "/", data: str = "")
    • send() -> Response - send the request
    • __repr__()
    • __str__()
  • Response(socket)
    • read()
    • close() - close the socket
    • .status - status code
    • .meta - meta string for the status
    • .file - socket file
    • .request - the Request object for this response
    • __repr__()
    • __str__()
  • Status - statuses
    • success = 2
    • redirect = 3
    • client_error = 4
    • server_error = 5
  • get(url: str, data: str = "") -> Response - if the query string part in the URL exists, data will be ignored.

TODO

  • invalid url handling
  • util functions like parsing meta and getting status type
  • basic CLI usage
  • async methods