Skip to main content

Library for spartan protocol

Project description

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

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

spartan-py-0.2.10.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

spartan_py-0.2.10-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file spartan-py-0.2.10.tar.gz.

File metadata

  • Download URL: spartan-py-0.2.10.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.7.3 Linux/4.19.0-14-amd64

File hashes

Hashes for spartan-py-0.2.10.tar.gz
Algorithm Hash digest
SHA256 dffa4cf944d67e34d8414a1e0d16a129393485e21c5244bba8ec1df258d75af1
MD5 6318ac80b16e2d0d4e3f307ab3295f15
BLAKE2b-256 c5412ec6e92414cc9598a3cd5f237249ce34ed1347058008c3a5061a3500f219

See more details on using hashes here.

File details

Details for the file spartan_py-0.2.10-py3-none-any.whl.

File metadata

  • Download URL: spartan_py-0.2.10-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.7.3 Linux/4.19.0-14-amd64

File hashes

Hashes for spartan_py-0.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 8bebd22aba0be4cb1a22d03af5d20225d6af4b904fcf2228795f92d3f40b7246
MD5 78425ae092515f3010ea818b9e927239
BLAKE2b-256 145a21b9f6ff825868901a672b233f69ca958223eeb0bd1798ffb798da551811

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