Giter Club home page Giter Club logo

aiosparql's Introduction

License

Build Status

Code Coverage

An asynchronous SPARQL library using aiohttp

Synopsis

from aiosparql.syntax import (
    IRI, Namespace, Node, PrefixedName, RDF, RDFTerm, Triples)

# define a namespace

class Boo(Namespace):
    __iri__ = IRI("http://boo#")
    SomeClass = PrefixedName
    website = PrefixedName
    label = PrefixedName

# create a node

node = Node("<subject>", {
    RDF.type: Boo.SomeClass,
    Boo.website: IRI("http://example.org"),
    Boo.label: "some label", # "some label" will be automatically escaped
})

# missing prefixed names will show on your IDE and fail on execution

print(Boo.something) # AttributeError!

# create triples

triples = Triples([("s", "p", "o")]) # o is automatically escaped
triples.append(("s", Boo.website, IRI("http://example.org")))
triples.extend([("s", Boo.website, IRI("http://example.org"))])

print(triples) # print the triples is a format usable directly in a SPARQL
               # query. It also groups by subject automatically for you


from aiosparql.client import SPARQLClient

client = SPARQLClient("http://dbpedia.org/sparql")
result = await client.query("select * where {?s ?p ?o} limit 1")
# result is a dict of the JSON result
result = await client.update("""
    with {{graph}}
    insert data {
        {{}}
    }
    """, triples)
# the triples will be automatically indented to produce a beautiful query


from aiosparql.escape import escape_any

print(escape_any(True)) # "true"
print(escape_any("foo")) # "foo"
print(escape_any(5)) # "5"
print(escape_any(5.5)) # "5.5"^^xsd:double

Installation

  • User space installation

    easy_install --user aiosparql
  • System wide installation

    easy_install aiosparql

Requirements

  • Python >= 3.5

Testing

In order for the tests to run, you must have the following Docker containers started:

docker run -d --name travis-virtuoso -p 8890:8890 -e SPARQL_UPDATE=true tenforce/virtuoso:1.2.0-virtuoso7.2.2
docker run -d -p 3030:3030 --name travis-fuseki -e ADMIN_PASSWORD=PASSWORD -e ENABLE_DATA_WRITE=true -e ENABLE_UPDATE=true -e ENABLE_UPLOAD=true secoresearch/fuseki

Credits

This software has been produced by Dacota One.

aiosparql's People

Contributors

asvetlov avatar atomsforpeace avatar cecton avatar dependabot-preview[bot] avatar webknjaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aiosparql's Issues

KeyError when query includes "UNION"

pretty much the title.

I'm a big fan of this package, it helped me alot in my Masterthesis but today I seemed to have trouble with it.

from aiosparql.client import SPARQLClient

async with SPARQLClient("https://dbpedia.org/sparql") as client:
       result = await client.query("select ?redirects where {{?redirects dbo:wikiPageRedirects dbr:Big_Trout_Lake} union {dbr:Big_Trout_Lake dbo:wikiPageRedirects ?redirects}}")

this query seems to break and infact every query that includes "UNION". For now I will try to work around it by quering the endpoint two times and concatinate the results afterwards but it would be cool if you could fix that issue.

Tests not working

Hi there, should pytest-aiohttp be installed or not? It's not in the test-requirements.txt but it's in the conftest file. When I have it installed all tests fail with

ValueError: option names {'--fast'} already added

When I don't have it installed the test_syntax and test-escape work but I get errors in 9/10 of the test_client tests. Some failures are these:

AttributeError: 'TestClient' object has no attribute 'query'

RuntimeError: There is no current event loop in thread 'MainThread'.

Relevant versions:

Python 3.5.2

aiohttp==2.3.10

pytest==4.3.1

Release v0.10.0

I think we are good for a new alpha release at this point. Can you show me how you normally do that?

Thanks

Looking for the project maintainer

@cecton, the project initial author, doesn't use Python anymore.
She is not interesting for aiosparql project support.

I never used sparql personally and overwhelmed by other Open Source projects.

The library is looking for a project maintainer.
The responsibility is not too high, maybe the biggest challenge for now is keeping the support of the newest Python and aiohttp versions.

I can help with any question, CI setup, etc. but really love to have the project owner who is responsible for communication with users and keeping updates working.

If somebody wants to be a champion -- please left a comment.

Improve test environment

  1. We could use a fixture to run the test server automatically for the integration tests.
  2. We could use py.test syntax which is simpler and clearer to rewrite all the tests.

(See discussion #27 (comment) )

Switch to github actions

Travis was a great tool but now it is barely nonfunctional for open source projects.
We need the migration to GitHub Workflows.

The change is obvious and trivial; a champion is needed.

Make a real documentation

Right now the only documentation is the synopsis in the README. We could provide much more documentation.

Add automatic deploy and pyup bot

  1. Most of projects has this feature so each team member can trigger deploy with git tag, should be easy to do
  2. we use pyup bot to watch updates in dependencies, very useful tool to find incompatibilities.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.