Skip to main content

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

Release files for spartan-py 0.2.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spartan-py 0.2.10
File Size Uploaded
spartan-py-0.2.10.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spartan-py 0.2.10
File Interpreter ABI Platform
spartan_py-0.2.10-py3-none-any.whl Python 3 none any Details

Total release size: 7.9 kB

Release files / spartan-py-0.2.10.tar.gz

Download URL spartan-py-0.2.10.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dffa4cf944d67e34d8414a1e0d16a129393485e21c5244bba8ec1df258d75af1
BLAKE2b-256 checksum
How to use checksums
c5412ec6e92414cc9598a3cd5f237249ce34ed1347058008c3a5061a3500f219
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.7.3 Linux/4.19.0-14-amd64

Release files / spartan_py-0.2.10-py3-none-any.whl

Download URL spartan_py-0.2.10-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bebd22aba0be4cb1a22d03af5d20225d6af4b904fcf2228795f92d3f40b7246
BLAKE2b-256 checksum
How to use checksums
145a21b9f6ff825868901a672b233f69ca958223eeb0bd1798ffb798da551811
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.7.3 Linux/4.19.0-14-amd64

Release history Release notifications | RSS feed

This release

0.2.10 This release

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page