Skip to main content

Sourcegraph Python Library

This Python library provides an interface to analyze and visualize code dependencies in GitHub repositories.

⚠️ Warning: Currently only supports Python repositories

Please note that this library is currently designed to work only with Python repositories. Analysis of repositories in other programming languages is not supported at this time.

Installation

You can install the Sourcegraph Python library using pip:

pip install sourcegraph

Usage

Here's how you can use the Sourcegraph library to analyze a GitHub repository:

from sourcegraph import Sourcegraph

# Initialize the Sourcegraph object with a repository URL
repo = Sourcegraph(repository_url='https://github.com/Ransaka/sinlib.git')

# Generate a dependency graph
repo.run()

# Plot the dependency graph
repo.plot()  # Supports different networkx compatible layouts when plotting

# Get properties of a specific node (function or class)
node_properties = repo.get_node_property('process_text')
print(node_properties)

# Get the total number of nodes in the repository
print(repo.n_nodes)

# Get all functions and classes in the repository
functions_and_classes = repo.get_functions_and_classes
print(functions_and_classes)

# Get dependencies of a specific class or function
tokenizer_dependencies = repo.get_dependencies("Tokenizer")
print(tokenizer_dependencies)

Features

  • Dependency Analysis: Analyze and visualize the dependencies between functions and classes in a GitHub repository.
  • Code Inspection: Retrieve detailed information about specific functions or classes, including their definitions and docstrings.
  • Visualization: Plot dependency graphs using networkx-compatible layouts.

Main Methods

  • run(): Generates the dependency graph for the specified repository.
  • plot(): Visualizes the dependency graph.
  • get_node_property(node_name): Retrieves properties of a specific node (function or class).
  • get_functions_and_classes: Returns a list of all functions and classes in the repository.
  • get_dependencies(node_name): Returns the dependencies of a specific function or class.

Example Output

Getting node properties:

repo.get_node_property('process_text')
# Output:
# {'type': 'function',
#  'name': 'process_text',
#  'definition': "def process_text(t):\n    ...",
#  'file_name': 'preprocessing.py',
#  'docstring': ''}

Getting all functions and classes:

repo.get_functions_and_classes
# Output:
# ['Romanizer', 'Tokenizer', 'Transliterator', 'load_tokenizer', ...]

Getting dependencies:

repo.get_dependencies("Tokenizer")
# Output:
# {'load_default_vocab_map', 'process_text'}

Limitations

  • Currently, this library only supports analysis of Python repositories. Repositories in other programming languages cannot be processed at this time.
  • The library assumes that the repository structure follows common Python project conventions.

Contributing

Contributions to improve the Sourcegraph Python library are welcome. Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For any queries or suggestions, please open an issue on the GitHub repository.

Metadata

Release files for sourcegraph 0.0.7

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

Source distribution (sdist)

Source distribution for sourcegraph 0.0.7
File Size Uploaded Provenance
sourcegraph-0.0.7.tar.gz 7.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sourcegraph 0.0.7
File Interpreter ABI Platform
sourcegraph-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / sourcegraph-0.0.7.tar.gz

Download URL sourcegraph-0.0.7.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e62d7e1392a046df1965feefee0aa6125a7b4f431db57c245693dc2e60f45c5d
BLAKE2b-256 checksum
How to use checksums
d68d41f90f8ab52e956a31376ba40460c0fb345f9ff0fd821fbaaf2bb7351e6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / sourcegraph-0.0.7-py3-none-any.whl

Download URL sourcegraph-0.0.7-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48b90548fb6337a8a5accafa2bb3a78b87a1c19bb50b0a58c0353eae7707baf4
BLAKE2b-256 checksum
How to use checksums
1e75e02b7b367335bead609d9e44f78d12ae72079e26f846444c1fd11631d0b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Security for sourcegraph 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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